Page 1 of 1

exception with ExecuteNonQuery();

Posted: Mon 20 Dec 2004 16:10
by theud
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 ....

Re: exception with ExecuteNonQuery();

Posted: Tue 21 Dec 2004 09:52
by Oleg
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.'