private void toolStripButton3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "" || textBox5.Text.Trim() == "" || textBox6.Text.Trim() == "" || textBox7.Text.Trim() == "" || textBox8.Text.Trim() == "" || comboBox1.Text.Trim() == "" || comboBox3.Text.Trim() == "")
{
MessageBox.Show("请输入完整信息!", "提示");
}
else
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=SSMS;Integrated Security=SSPI");
string sql1, sql2, sql3, sql4;
sql1="update Student set Sname='"+textBox1.Text.ToString()+"',Birthdate="+textBox8.Text.ToString()+",Born='"+textBox7.Text.ToString()+"',Tel='"+textBox2.Text.ToString()+"',";
sql2 = "IDcard='" + textBox3.Text.ToString() + "',State='" + textBox4.Text.ToString() + "',Pwd='" + textBox5.Text.ToString() + "',Transactions='" + textBox6.Text.ToString() + "',";
sql3="where SID='"+toolStripTextBox1.Text.ToString()+"'";
sql4=sql1+sql2+sql3;
cn.Open();
SqlCommand aqc = new SqlCommand(sql4,cn);
aqc.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
comboBox1.Text = "";
comboBox3.Text = "";
MessageBox.Show("学生信息修改成功", "提示");
cn.Close();
} }这个修改学生信息的c#代码哪儿错了啊?
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" || textBox4.Text.Trim() == "" || textBox5.Text.Trim() == "" || textBox6.Text.Trim() == "" || textBox7.Text.Trim() == "" || textBox8.Text.Trim() == "" || comboBox1.Text.Trim() == "" || comboBox3.Text.Trim() == "")
{
MessageBox.Show("请输入完整信息!", "提示");
}
else
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=SSMS;Integrated Security=SSPI");
string sql1, sql2, sql3, sql4;
sql1="update Student set Sname='"+textBox1.Text.ToString()+"',Birthdate="+textBox8.Text.ToString()+",Born='"+textBox7.Text.ToString()+"',Tel='"+textBox2.Text.ToString()+"',";
sql2 = "IDcard='" + textBox3.Text.ToString() + "',State='" + textBox4.Text.ToString() + "',Pwd='" + textBox5.Text.ToString() + "',Transactions='" + textBox6.Text.ToString() + "',";
sql3="where SID='"+toolStripTextBox1.Text.ToString()+"'";
sql4=sql1+sql2+sql3;
cn.Open();
SqlCommand aqc = new SqlCommand(sql4,cn);
aqc.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
comboBox1.Text = "";
comboBox3.Text = "";
MessageBox.Show("学生信息修改成功", "提示");
cn.Close();
} }这个修改学生信息的c#代码哪儿错了啊?
都加上trim()
使用string.IsNullOrEmpty判断
sql2 = "IDcard='" + textBox3.Text.ToString().Trim()+ "',State='" + textBox4.Text.ToString().Trim()+ "',Pwd='" + textBox5.Text.ToString().Trim()+ "',Transactions='" + textBox6.Text.ToString().Trim() + "',";
sql3="where SID='"+toolStripTextBox1.Text.ToString().Trim()+"'";
这样吗 可是还是有错误啊
'0' 附近有语法错误。(错误)
sql2 = "name='" + textBox2.Text.ToString() + "',race='" + textBox3.Text.ToString() + "',address='" + textBox4.Text.ToString() + "',telephone='" + textBox5.Text.ToString() + "',postalcode='" + textBox6.Text.ToString() + "',re='" + textBox7.Text.ToString() + "'";
sql3 = "where studentnumber='" + comboBox5.Text.ToString() + "'";
sql4 = sql1 + sql2 +sql3;
这是我看到的类似的代码 他这个可以啊