Zeb Muhammad

Zeb Muhammad

  • NA
  • 67
  • 18.2k

DataGridView Date save

Jul 29 2017 8:00 AM
Dear Friends,
I want to save Date from DataGridView to Database.
my Date Datatype is DateTime in DB.
please, check my code
private void button4_Click(object sender, EventArgs e)
{
con.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
SqlCommand cmd = new SqlCommand("INSERT INTO cat1_tab (myDate) VALUES(@myDate)", con);
cmd.Parameters.Add("@mydate",dataGridView1.Rows[i].Cells[7].Value.ToString("yyyy-MM-dd"));
cmd.ExecuteNonQuery();
MessageBox.Show("save");
con.Close();
}
}
Thx 
 

Answers (2)