Click to See Complete Forum and Search --> : Error In insertion in VC++


kittaiyya
April 8th, 2008, 08:11 PM
Hello There,

I am trying to insert variables in mysql database.

I have a Dialog based application which when clicked OK, inserts some data into the database

But i am getting this error "Parameter '?' must be defined."

Here is my code


CString ip_add="123.123.123";

MySqlConnection ^conn;
MySqlCommand ^cmd;
conn=gcnew MySqlConnection(L"Data Source=localhost;database=demographics;Persist Security Info=yes;uid=root;Password=toor");
cmd = gcnew MySqlCommand(L"Insert into user_demo(userid) values(?ip_add)", conn);
conn->Open();
cmd->ExecuteNonQuery();
MessageBox("hello",NULL,0);
conn->Close();


When i pass just values it works ok, but if i store the values in a variable and send it then it gives the Parameter ?ip_add must be defined

I am assuming that ? is the way of indicating that it is the variable and the original value of the variable needs to be sent.

Any kind of help would be appreciated

regards
Kittu

Skizmo
April 9th, 2008, 02:53 AM
Wrong forum. Your code is managed (http://www.codeguru.com/forum/forumdisplay.php?s=&forumid=17) code. Not standard C++.

Marc G
April 9th, 2008, 03:10 AM
[ moved thread ]

Marc G
April 9th, 2008, 03:12 AM
I never used MySqlCommand myself, but you somehow need to link your variable.
Take a look at http://www.java2s.com/Code/CSharp/Database-ADO.net/IllustrateshowtoperformINSERTUPDATEandDELETEstatementsusingADONET.htm It's for C#, but easily translated to managed C++ I guess. The important thing I'm talking about is "mySqlCommand.Parameters.Add(...)"