我必须使用插入查询在表中插入值...存储在数据库中的表有 3 列: 1. 日期 (DateTime) 2. SensorValue (Float) 3. 差异 (Float) 现在每列的值来自datagridview .....这是按钮的插入代码
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\dbsave.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
if (con.State == ConnectionState.Closed)
{
con.Open();
}
for (Int32 i = 0; i < dataGridView1.Rows.Count-1; i++)
{
String query1 =
"INSERT INTO " + tbName +
" ( Date, SensorValue, Difference) " + "VALUES (" +
dataGridView1.Rows[i].Cells[0].Value + "," +
dataGridView1.Rows[i].Cells[1].Value + "," +
dataGridView1.Rows[i].Cells[2].Value + ")";
SqlCommand cmd1 = new SqlCommand(query1, con);
cmd1.ExecuteNonQuery();
}
con.Close();
MessageBox.Show("The table has been saved");
错误当然是在执行查询时....日期列中的第一个条目是值:12/05/2012 14:32:00....所以基本上 sql 不接受放置的冒号14....我该如何解决这个问题?请帮忙