新手求助,请问以下关于c#三层架构的删除,哪里有问题?

DAL层的代码:
public int DeleteUserinfo(string name,string pwd)
{
SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=;");
string sql = "delete from userinfo where name='" + name + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int r = cmd.ExecuteNonQuery();
con.Close();
return r;
}
BLL层的代码:
public int DeleteUserinfo(string name)
{
UserInfoDAL dal = new UserInfoDAL();
return dal.DeleteUserinfo(name);
}
click中的代码:

private void btnDelete_Click(object sender, EventArgs e)
{

int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
userInfoBLL bll = new userInfoBLL();
bll.DeleteUserinfo(id);
}
新手,哪有问题的,求解。

杨魅力
浏览 219回答 3
3回答

鸿蒙传说

bll.DeleteUserinfo(id);常识性错误id是int,他这里只起到索引作用使用字符串,表示要删除的数据

扬帆大鱼

调用BLL层的DeleteUserinfo()方法,但传进去的参数是个string型的string name = dataGridView1.SelectedRows[0].Cell[0].Value.ToString;int res = new userInfoBll().DeleteUserinfo(name);记得引进BLL命名空间

FFIVE

BLL中 return dal.DeleteUserinfo(name);DAL层DeleteUserinfo(string name,string pwd)DAL层参数没有传对,还少传一个
打开App,查看更多内容
随时随地看视频慕课网APP