我的代码就是按钮
try
{
con.Open();
OleDbCommand cmd = new OleDbCommand("insert into slogin values('" + todayDay + "','" + txtDate.Text + "','" + cboStudentNo + "','" + txtLastName + "','" + txtFirstName + "','" + cboComputerNo + "')", con);
cmd.ExecuteNonQuery();
// OleDbCommand cmd2 = new OleDbCommand("update into Computer set Status='Occupied'where PcNumber='" + cboComputerNo.Text + "'", con);
// cmd2.ExecuteNonQuery();
con.Close();
Computer();
Student();
dgv();
time();
MessageBox.Show("login success");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
答案 0 :(得分:1)
尝试:
OleDbCommand cmd = new OleDbCommand("insert into slogin values('" + todayDay.Text + "','" + txtDate.Text + "','" + cboStudentNo.SelectedValue.Text + "','" + txtLastName.Text + "','" + txtFirstName.Text + "','" + cboComputerNo.SelectedValue.Text + "')", con);``
即使你不问,你应该使用参数出于安全原因输入明文: Using Parameters in Sql Statements