format date
-
hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)
jing
-
hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)
jing
You should use Parameter to make it easier instead of formatting datetime. string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (
?
)"; MySqlCommand command = new MySqlCommand(query, connection);command.Parameters.Add(new MySqlParameter("pDate",dateneeded));
command.ExecuteNonQuery();It seem to be a solution or an answer.
-
You should use Parameter to make it easier instead of formatting datetime. string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (
?
)"; MySqlCommand command = new MySqlCommand(query, connection);command.Parameters.Add(new MySqlParameter("pDate",dateneeded));
command.ExecuteNonQuery();It seem to be a solution or an answer.
hi, thanks...il try this one... i appreciate it... regards:) ;)
jing
-
hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)
jing
you just have to use the datetimepicker properties/methods datetimepicker.value (one way to get the datetimepicker value)
-
hi, how to insert the value of my datetimepicker to my database table? this is my code: private void button6_Click(object sender, EventArgs e) { try { string dateneeded = dateTimePicker6.Value.ToLongDateString(); String query = "INSERT INTO purchaserequest(dateneeded) VALUES (DATE_FORMAT(dateneeded,'%Y-%m-%d')"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); } catch (MySqlException mse) { MessageBox.Show(mse.Message); } } its not working:) thanks in advance:) regards:)
jing
jing, You can try an essy way out. Just put the "date-time" in single quote while preparing sql string. i.e. your query string should be changed as below: String query = "INSERT INTO purchaserequest(dateneeded) VALUES (" + "'" + dateneeded + "'" + )"; Also please check you have the correct column name. Manoj
-
jing, You can try an essy way out. Just put the "date-time" in single quote while preparing sql string. i.e. your query string should be changed as below: String query = "INSERT INTO purchaserequest(dateneeded) VALUES (" + "'" + dateneeded + "'" + )"; Also please check you have the correct column name. Manoj
thats it!! tnx!
jing