exception with ExecuteNonQuery();

exception with ExecuteNonQuery();

Postby theud » Mon 20 Dec 2004 16:10

HI. I have this error
"non handled exception 'System.InvalidOperationException' incorelab.mysql.dll

added information : Connection property has not been initialized"

with this simple VC++.net program, at the line myCommand->ExecuteNonQuery();


#include "stdafx.h"

#using
#using
#using
#using
using namespace System;
using namespace System::Data;
using namespace CoreLab::MySql;

int main() {
String* q="INSERT INTO `accor` ( `date` , `open` , `high` , `low` , `close` ) VALUES ('2004-05-01', '10', '1', '1', '1')";
MySqlCommand *myCommand = new MySqlCommand(q);
MySqlConnection * cntd= new MySqlConnection("User=root;Host=localhost;Port=3306;Database=td");
cntd->Open();
myCommand->ExecuteNonQuery();
cntd->Close();
return 0;
}

Could you explained it to me. Strangely, it worked once, and then never ....
theud
 

Re: exception with ExecuteNonQuery();

Postby Oleg » Tue 21 Dec 2004 09:52

You should add this row to your code:
Code: Select all
myCommand->Connection = cntd

Just it was specified in the exception: 'Connection property has not been initialized.'
Oleg
Devart Team
 
Posts: 264
Joined: Thu 28 Oct 2004 13:56


Return to dotConnect for MySQL