im having a problam inserting a string that looks like a date (23.02.2015) from datagridview to my local database date column that .
i know i need to transfer my string "23.02.2015" to 23/02/2015 and convert it to a date variable before im inserting it to my database date column but i dont know how to do it inside my code :
private void button3_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string constring = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\john\Documents\Visual Studio 2015\Projects\Project\Project\DB.mdf;Integrated Security=True";
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO ResultsTable VALUES(@Date, @TagNumber)", con))
{
cmd.Parameters.AddWithValue("@Date", row.Cells["Exposure Date"].Value);
cmd.Parameters.AddWithValue("@TagNumber", row.Cells["Device #"].Value);
cmd.ExecuteNonQuery();
}
}
}
MessageBox.Show("Records inserted.");
}
in short - im having a problam to convert a string like "23.05.2014" to a date type like 23/05/2014 to insert it to date column in my database in my code .