string connString = "server = .;database = sztsl; integrated security = true";
private void btnDadd2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sql = string.Format("insert into Daily(Date,StarTime,Endtime,Person,Failure,Reason,Solution,Message) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'",txtDdate.Text, txtDstartime.Text, txtDendtime.Text, txtDperson.Text, txtDfailure.Text, txtDreason.Text, txtDstartime.Text, txtDmessage.Text);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
**int x = cmd.ExecuteNonQuery();** 調試提示這裡:附近有語法錯誤
conn.Close();
if (x >= 1)
MessageBox.Show("Succeed", "Prompt",MessageBoxButtons.OK);
MessageBox.Show("Failure", "Prompt", MessageBoxButtons.OK);
}
找到原因了,sql語句中少了個:)。真是麻煩大家了。