Hi all fri, i'd like to know how to pro-grammatically insert variable data to MySQL database . I m succeed in fixed data insert only. i wanna import variable data which might be generated by user on run time. Here's my code. I use MySQL Command Line Client . It always insert 'NULL' into all columns. Pls help for such a newbie in database. When i use Microsoft sql server management studio express 2005 ,
it was successfully worked. Pls help me . i need it urgently :
very much appreciate if you can show some other possible way . thanks
(
string host = "localhost";
string database = "TEST";
string user = "root";
string password = "12345";
string strProvider = "Data Source=" + host + ";Database=" + database + ";User ID=" + user + ";Password=" + password;
//string strSQL_W = "INSERT INTO key_store(FileID, FileName, KeyFile, //DateCreated) VALUES('5','TESTFILE_3','55555','2010-12-5')";
try
{
MySqlConnection mysqlCon = new MySqlConnection(strProvider);
mysqlCon.Open();
if (mysqlCon.State.ToString() == "Open")
{
MySqlCommand mysqlCmd = new MySqlCommand();
mysqlCmd.Connection = mysqlCon;
mysqlCmd.Parameters.AddWithValue("@FileID", FileID);
mysqlCmd.Parameters@FileID.Direction = ParameterDirection.Input;
mysqlCmd.Parameters.AddWithValue("@FileName", keyfilename_m);
mysqlCmd.Parameters@FileName.Direction = ParameterDirection.Input;
mysqlCmd.Parameters.AddWithValue("@TestFile", key);
mysqlCmd.Parameters@TestFile.Direction = ParameterDirection.Input;
mysqlCmd.Parameters.AddWithValue("@DateCreated", DateTime.Now.Date);
mysqlCmd.Parameters @DateCreated.Direction = ParameterDirection.Input;
mysqlCmd.ExecuteNonQuery();
MessageBox.Show("Data Import Successfully.");
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
mysqlCon.Close();