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