private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "" ||
textBox4.Text.Trim() == "" || textBox5.Text.Trim() == "" || textBox6.Text.Trim() == "")
{
MessageBox.Show("数据不完整! 请重新输入");
return;
}
SqlConnection conn = new SqlConnection(strcon);
string sql = "INSERT INTO View_1 VALUES(" + textBox1.Text.Trim() + ",'" + textBox2.Text.Trim()
+ "'," + textBox3.Text.Trim() + "," + textBox4.Text.Trim() + ",'"
+ textBox5.Text.Trim() + "','" + textBox6.Text.Trim() + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter xuhao = new SqlParameter("@in_xuhao", SqlDbType.Int);
xuhao.Direction = ParameterDirection.Input;
xuhao.Value = textBox1.Text.Trim();
cmd.Parameters.Add(xuhao);
SqlParameter Tit = new SqlParameter("@in_Tit", SqlDbType.Char, 30);
Tit.Direction = ParameterDirection.Input;
Tit.Value = textBox2.Text.Trim();
cmd.Parameters.Add(Tit);
SqlParameter price = new SqlParameter("@in_price", SqlDbType.Int);
price.Direction = ParameterDirection.Input;
price.Value = textBox3.Text.Trim();
cmd.Parameters.Add(price);
SqlParameter number = new SqlParameter("@in_number", SqlDbType.Int);
number.Direction = ParameterDirection.Input;
number.Value = textBox4.Text.Trim();
cmd.Parameters.Add(number);
SqlParameter press = new SqlParameter("@in_press", SqlDbType.Char, 30);
press.Direction = ParameterDirection.Input;
press.Value = textBox5.Text.Trim();
cmd.Parameters.Add(press);
SqlParameter Huang = new SqlParameter("@in_Huang", SqlDbType.Char, 10);
Huang.Direction = ParameterDirection.Input;
Huang.Value = textBox6.Text.Trim();
cmd.Parameters.Add(Huang);
try
{
conn.Open();
int a = cmd.ExecuteNonQuery();
if (a != 0)
{
MessageBox.Show("添加成功");
}
}
catch
{
MessageBox.Show("添加出错!");
}
finally
{
conn.Close();
}
}
评论0
最新资源