我正在进行考勤登记。我正在使用下面的代码..这里插入查询工作正常和时间成功保存在数据库timein字段中。更新查询也成功执行,但数据库没有更新......任何人请帮忙...
private void checkin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source............");
conn.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "insert into timeatten (id,name,timein)values('" +comboBox1.Text+"','"+textBox1.Text+"','"+textBox2.Text+"' )";
comm.Connection = conn;
comm.ExecuteNonQuery();
MessageBox.Show("Successfully check in");
conn.close();
}
private void checkout_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source.............");
conn.Open();
SqlCommand comm = new SqlCommand();
comm.CommandText = "update timeatten set timeout='" + textBox2.Text + "' where id='" + comboBox1.Text +"'";
MessageBox.Show("Successfully Checkout");
conn.close();
}
答案 0 :(得分:2)
我认为你在checkout_Click中错过了这两行:
comm.Connection = conn;
comm.ExecuteNonQuery();