[C#] 纯文本查看 复制代码 private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=PENGCHEN;uid=sa;pwd=123;database=Student");
con.Open();
string name = textBox1.Text;
int h = int.Parse(textBox2.Text);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into Table1 values ("+name+","+h+") ";
cmd.Connection = con;
int i = cmd.ExecuteNonQuery();
con.Close();
if (i == 1)
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("on");
}
}
我向数据库写入信息 这样能成功,为什么少了一段代码会失败[C#] 纯文本查看 复制代码 private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=PENGCHEN;uid=sa;pwd=123;database=Student");
con.Open();
string name = textBox1.Text;
int h = int.Parse(textBox2.Text);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into Table1 values ("+name+","+h+") ";
cmd.Connection = con;
con.Close();
}
少了这一段 验证是否成功的代码应该不会失败吧?但是为什么 无法写入?
|