删除数据总是失败
public class PersonOperate
{
public PersonOperate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static bool FindPerson(int pID)//建立静态方法查找用户是存在(int pID)
{
SqlConnection conn = DB.conCreate();
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select count(*) from test where pID='" + pID + "'";
//cmd.CommandText = "select count(*) from adonettest where UserName='" +username+ "'";
cmd.Connection = conn;
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)//表示用户已经存在
{
return true;
}
else
{
return false;//可以注册,数据库目前还没有该用户
}
}
public static bool InsertOperate(Person insert)//建立插入数据的静态方法
{
try
{
SqlConnection conn = DB.conCreate();
conn.Open();
SqlCommand cmd = new SqlCommand();
//cmd.CommandText = "insert into adonettest values(@pID,@pName,@pSex)";
cmd.CommandText = "insert into test values(@pID,@pName,@pSex)";
cmd.Connection = conn;
SqlParameter para = new SqlParameter("@pID", SqlDbType.Int);//插入姓名
para.Value = insert.pID;//把Poerson类声明的变量pID赋给para
cmd.Parameters.Add(para);
para = new SqlParameter("@pName", SqlDbType.VarChar, 50);//插入密码
para.Value = insert.pName;//把Poerson类声明的变量pName赋给para
cmd.Parameters.Add(para);
//para = new SqlParameter("@pPwd", SqlDbType.VarChar, 20);
//para.Value = insert.pUserPwd;
//cmd.Parameters.Add(para);
para = new SqlParameter("@pSex", SqlDbType.VarChar, 2);//选择性别
para.Value = insert.pSex;//把Poerson类声明的变量pSex赋给para
cmd.Parameters.Add(para);
//cmd.ExecuteScalar();
cmd.ExecuteNonQuery();
conn.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
public static DataTable SelectAllPoerson()//建立查询用户的静态方法
{
SqlConnection conn = DB.conCreate();
conn.Open();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from test", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
return ds.Tables["table"];
}
public static bool DelOperate(int pID)//建立删除用户的方法
{
try
{
SqlConnection conn = DB.conCreate();
conn.Open();
SqlCommand cmd = new SqlCommand("delete from test where pID='" + pID + "'");
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
return true;
}
catch (Exception ex)
{
return false;
}
}
public static bool UpdateOperate(Person update)//建立更新