My System date format is customized as dd/MM/yyyy
when i enter date e.g 25/02/2016 than in textbox c# windows form, it gives error System.Data.SqlClient.SqlException
My Code is given below
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Test;User ID=abc; Password=****");
SqlDataAdapter sda = new SqlDataAdapter("insert into dates values('"+textBox1.Text.ToString()+"')",con);
DataTable dt = new DataTable();
sda.Fill(dt);
MessageBox.Show("Data Inserted");

Ranjit PowarRank #553 · 4.4K reputationPosted Feb 28, 2016, 10:23 PM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 27, 2016, 5:52 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Feb 27, 2016, 9:45 PM EST
DateTime dt=DateTime.ParseExact(textBox1.Text,"dd/MM/yyyy",CultureInfo.InvariantCulture);
SqlDataAdapter sda = new SqlDataAdapter("insert into dates values('"+dt.Value+"')",con);
DataTable dt = new DataTable();
Mehboob Ali25 reputationPosted Feb 28, 2016, 9:02 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Feb 28, 2016, 9:17 PM EST
Mehboob Ali25 reputationPosted Feb 28, 2016, 10:11 PM EST
Raja TRank #685 · 3.5K reputationPosted Feb 28, 2016, 10:33 PM EST
Mehboob Ali25 reputationPosted Feb 28, 2016, 11:16 PM EST
Raja TRank #685 · 3.5K reputationPosted Feb 28, 2016, 11:22 PM EST
Mehboob Ali25 reputationPosted Feb 28, 2016, 11:23 PM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Feb 28, 2016, 11:24 PM EST