62,046
社区成员
发帖
与我相关
我的任务
分享
string connection = "Data Source=(local);Initial Catalog=product;Integrated Security=True";
SqlConnection sqlConnection1 = new SqlConnection(connection);
SqlCommand myCommand = sqlConnection1.CreateCommand();
string No, grade, price;
switch (e.CommandName)
{
case "ok":
No = ((Label)e.Item.FindControl("Label1")).Text;
myCommand.CommandText = "select 等级,单价 from fruitInfo where 商品编号='" + No + "'";
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
myDataAdapter.SelectCommand = myCommand;
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "fruitInfo");
//提取用户输入 的数据
grade = ((TextBox)e.Item.FindControl("TextBox1")).Text;
price = ((TextBox)e.Item.FindControl("TextBox2")).Text;
myCommand.CommandText = "update fruitInfo set 等级='" + grade + "',单价='" + price + "' where 商品编号='" + No + "'";
try
{
sqlConnection1.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception)
{
Response.Write("<script>alert('数据格式错误')</script>");
}
finally
{
sqlConnection1.Close();
}
break;
}
MyDataBind();//自己的一个方法 绑定数据用的
Label lb = (Label)e.Item.FindControl("Label1");
No =lb.Text;
((Label)(e.Item.FindControl("Label1"))).Text