using (Conn = new SqlConnection(ConnectionString))
{
//DataAdapter更新数据
Conn.Open();//打开数据库连接
string sqlstr = "select * from UserInfo2 where UserName = @UserName";
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand updatecmd = new SqlCommand(sqlstr, Conn);
updatecmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = "小王";
SqlCommandBuilder cb = new SqlCommandBuilder(da);//自动生成插入数据的SQL语句,不能少
da.SelectCommand = updatecmd;
DataSet ds = new DataSet();
int count = da.Fill(ds, "UserInfo2");
if (count > 0)
{
ds.Tables["UserInfo2"].Rows[0]["Pwd"] = "111";//修改列值
da.Update(ds, "UserInfo2");//将DataSet中的数据更新到数据库
}
ds.Clear();
Response.Write("更新数据成功!");
}