照书上写的代码有问题`急诊啊
UserBll ub1 = ub;
SqlCommand sqlcom = new SqlCommand( "insert into AdUser values( '@User ', '@Password ', '@WebsiteName ', '@WebsiteAddress ' ", Sqlcon);
SqlParameter sqlpar_User = new SqlParameter();
sqlpar_User.ParameterName = "@User ";
sqlpar_User.Value = ub1.User;
sqlpar_User.DbType = DbType.String;
sqlcom.Parameters.Add(sqlpar_User);
SqlParameter sqlpar_Password = new SqlParameter( "@Password ", ub1.Password);
sqlcom.Parameters.Add(sqlpar_Password);
SqlParameter sqlpar_WebsiteName = new SqlParameter( "@WebsiteName ", ub1.WebsiteName);
sqlcom.Parameters.Add(sqlpar_WebsiteName);
SqlParameter sqlpar_WebsiteAddress = new SqlParameter( "@WebsiteAddress ", ub1.WebsiteAddress);
sqlcom.Parameters.Add(sqlpar_WebsiteAddress);
我到数据库中查看发现存入的不是业务层ub1的值 而直接都是字符串
@User @Password @WebsiteName @WebsiteAddress
sqlparameter 是不是有问题`?我也跟踪了 发现ub1的值有传进来
眼睛痛啊`救命啊
------解决方案--------------------SqlCommand sqlcom = new SqlCommand( "insert into AdUser values(@User,@Password,@WebsiteName,@WebsiteAddress ", Sqlcon);
不要 ' '
------解决方案--------------------ztwz(成长的烦燥(钱,女人)可偶什么都没有:() 的是正确的.
是你的语法有错误!
参数是不需要是用引号括起来的.
也可以这样写:
string sqlstr= "insert into AdUser values(@User,@Password,@WebsiteName,@WebsiteAddress) ";
SqlCommand sqlcom = new SqlCommand(sqlstr, Sqlcon);
把他们分开写,这样看起来也比较清晰.
------解决方案--------------------少了一个括号
------解决方案--------------------SqlCommand sqlcom = new SqlCommand( "insert into AdUser values(@User,@Password,@WebsiteName,@WebsiteAddress) ", Sqlcon);
还少个括号