protected void Button1_Click(object sender, EventArgs e)
{
string SqlStr = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection conn = new SqlConnection(SqlStr);
conn.Open();
string sql3 = "select 编号 from CS where 编号 = '" + TextBox1.Text.Trim() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
cmd3.CommandText = sql3;
cmd3.Connection = conn;
try
{
string BH = cmd3.ExecuteScalar().ToString();
string sql2 = "update CS set 数量 = 数量+1 where 编号 = " + TextBox1.Text.Trim();
SqlCommand cmd2 = new SqlCommand(sql2, conn);
Response.Write("<script>alert('插入成功')</script>");
}
catch
{
string sql1 = "insert into CS (编号,索书号,书名,作者,数量) values (";
sql1 += "'" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox3.Text.Trim() +
"','" + TextBox4.Text.Trim() + "','" + "1" + "')";
SqlCommand cmd1 = new SqlCommand(sql1, conn);
Response.Write("<script>alert('插入成功')</script>");
}
conn.Close();
}
第一条语句执行没问题,后面两条语句不报错但没有结果,我的是SQL数据库