参数化查询 '(@p1 char(8000),@p2 char(8000),@p3 char(8000),@p4 char(8000),@p5' 需要参数...
参数化查询 '(@p1 char(8000),@p2 char(8000),@p3 char(8000),@p4 char(8000),@p5' 需要参数 '@p1',但未提供该参数,具体代码如下:
protected void Button3_Click(object sender, EventArgs e)
{
//以下代码是连接到一个叫“Goods”的表从而对用户输入的Id进行查询
String s = "Data Source = win-9kv8nfp44mo;Initial Catalog = test.db;Integrated Security = true";
SqlConnection connection = new SqlConnection(s);
SqlCommand cmd = connection.CreateCommand();
connection.Open();
cmd.CommandText = "SELECT Goods_Id, Goods_Name,Goods_Num FROM Goods";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
adapter.InsertCommand = cmdBuilder.GetInsertCommand();
adapter.DeleteCommand = cmdBuilder.GetDeleteCommand();
adapter.UpdateCommand = cmdBuilder.GetUpdateCommand();
adapter.Fill(ds);
DataTable dt = ds.Tables["Table"];
//dt.Rows.Add(new object[] { "011", "banana", 50 }); //
//adapter.Update(ds); //这两行我添加数据的时候可以添加的
int flag = 0;
if (this.TextBox2.Text == "" || this.TextBox3.Text == "")
{
this.Label4.Text = "请完成以上信息后确认预订";
}
else
{
foreach (DataRow row in dt.Rows)
{
string bb = row["Goods_Id"].ToString().Trim();
if (bb.Equals(this.TextBox2.Text))
{
flag = 1;
int cc = int.Parse(row["Goods_Num"].ToString()) - Int32.Parse(this.TextBox3.Text);
this.Label4.Text = "预订成功,管理员会尽快处理您的预订要求,预订后产品还剩" + cc;
//以下部分是将用户提交的订单信息传递到一个“预订”数据表
SqlCommand cmd1 = connection.CreateCommand();
//connection.Open(); 这里说数据库已经打开无需再打开
cmd1.CommandText = "SELECT Custom_Name, Good_Id, Num FROM 预订";
SqlDataAdapter adapter1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
SqlCommandBuilder cmdBuilder1 = new SqlCommandBuilder(adapter);
adapter1.InsertCommand = cmdBuilder1.GetInsertCommand();
adapter1.DeleteCommand = cmdBuilder1.GetDeleteCommand();
adapter1.UpdateCommand = cmdBuilder1.GetUpdateCommand();
adapter1.Fill(ds1);
DataTable dt1 = ds1.Tables["Table"];
//dt1.Rows.Add(new object[]{this.TextBox4.Text.ToCharArray(), this.TextBox2.Text.ToCharArray(), Int32.Parse(this.TextBox3.Text)});
dt1.Rows.Add(new object[]{"test2_name","test2_id",0});
adapter1.Update(ds1); //就在这行报错,如最上面所写的
//dt1.AcceptChanges();
//dt.Rows.RemoveAt(this.);
//row.Delete();
ret