1, colleagues defines a database, which contains a field named long, and c # reserved word moniker
2, I define a textBox4 controls, in the picture and 1 button button, want to click a button, to insert data into a textBox4 numerical control,
int mlong=the Convert. ToInt32 (TextBox4. Text);
String ConnectionStr="server=localhost; Port=3306; User Id=root; Password=12345678; The database=cableid; Allow the User Variables=True ";
MySqlConnection Connection=new MySqlConnection (ConnectionStr);
MySqlCommand command=new MySqlCommand ();
Command. The Connection=Connection;
Try
{
Connection. The Open ();
MySqlCommand CMD=new MySqlCommand (" insert into table1 set mlong=@ long, "the Connection).
CMD. The Parameters. AddWithValue (" @ long, "mlong);
If (CMD) ExecuteNonQuery () & gt; 0)
{
Response. Write (" & lt; script> Alert (' add success) & lt;/script>" );
}
The else
{
Response. Write (" & lt; script> Alert (' add failure) & lt;/script>" );
}
}
The catch (Exception ex)
{
Response. Write (" & lt; script> Alert (ex. Message) & lt;/script>" );
}
Now exists the question is: not cut into the database, there is no any response,
CodePudding user response:
, defining a field called long, the field name and c # reserved word long name repetition,in the following way
int mlong=the Convert. ToInt32 (TextBox4. Text);
MySqlCommand CMD=new MySqlCommand (" insert into table1 set mlong=@ long, "the Connection).
CMD. The Parameters. AddWithValue (" @ long, "mlong);
CMD. ExecuteNonQuery ();
Cannot be mlong inserted into a database,
Two, but as long as the field name in the database is modified to mlong,
in the following way
Int mlong=the Convert. ToInt32 (TextBox4. Text);
MySqlCommand CMD=new MySqlCommand (" insert into table1 set mlong=@ mlong, ", Connection).
CMD. The Parameters. AddWithValue (" @ mlong, "mlong);
CMD. ExecuteNonQuery (); [/code]
Mlong can be inserted into the database,
CodePudding user response:
Keyword name repetition, can add the at symbolCodePudding user response: