Code:
private void button1_Click(object sender, EventArgs e)
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO (StartDate)
VALUES(@StartDate)", conn))
{
cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text);
cmd.ExecuteNonQuery();
}
}
I wanted the format the user wrote in TextBox to be this:
When I write this value in the textbox and click the button it generates this error: The conversion of a data type nvarchar into a data type datetime in> resulted in a value out of range.2017-09-26 11: 24: 39,693
How do I fix it?
Another question, how can I make a DateTimePicker in this format:
2017-09-26 11: 24: 39,693
And send it to the database when you click the button, same as the above code?