private void btnSave_Click(object sender, EventArgs e)
{
if (this.Text == "Add")
{
cmd.Connection = cn;
cmd.CommandText = string.Format(@"INSERT INTO LibraryInfo (First_Name,MI,Last_Name,Address,Municipality,Province,textbox7) VALUES('{0}','{1}','{2}','{3}','{4}',{5}','{6}')",
txtFName.Text.Trim(),
txtMI.Text.Trim(),
txtLName.Text.Trim(),
txtAddress.Text.Trim(),
cboMunicipality.Text.Trim(),
cboProvince.Text.Trim(),
textbox.Text.Trim());
}
else
{
cmd.Connection = cn;
cmd.CommandText = string.Format(@"UPDATE LibraryInfo SET First_Name='{0}',MI='{1}',Last_Name='{2}',Address='{3}',Municipality='{4}',Province='{5}',textbox7='{6}' WHERE ID={7}",
txtFName.Text.Trim(),
txtMI.Text.Trim(),
txtLName.Text.Trim(),
txtAddress.Text.Trim(),
cboMunicipality.Text,
cboProvince.Text,
textbox.Text.Trim(),
txtID.Text);
}
cmd.ExecuteNonQuery();
MessageBox.Show("Record Updated");
this.Dispose();
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
//它說:查詢表達式'Cavite','Graduate')'中的語法錯誤(缺少運算符)。 //甲米地是省和研究生是textbox7cmd.ExecuteNonQuery()缺少運算符
嘆息;不要將用戶輸入輸入到SQL中。永遠。 – 2014-09-22 12:53:57