public int Add(Model.Categories model) 这方法要怎么用
菜鸟求助;
问题有几个第一: 写一个添加方法老提示
我编译器错误消息: CS0029: 无法将类型“int”隐式转换为“bool”
源错误:
行 25: BLL.Categories bllca = new BLL.Categories();
行 26: //SQLServerDAL.Categories dalca = new SQLServerDAL.Categories();
行 27: if (bllca.Add(model))
行 28: Response.Write("添加成功");
行 29:
protected void btpost_Click(object sender, EventArgs e)
{
Model.Categories model = new Model.Categories();
model.CategoryName = bt2.Text;
BLL.Categories bllca = new BLL.Categories();
if (bllca.Add(model))
Response.Write("添加成功");
}
这个BLL层的代码:
public int Add(Model.Categories model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into [Categories](");
strSql.Append("[CategoryName],[Description],[Picture])");
strSql.Append(" values (");
strSql.Append("@CategoryName,@Description,@Picture)");
strSql.Append(";select @@Identity");
SqlParameter[] parameters = {
new SqlParameter("@CategoryName", SqlDbType.NVarChar,15),
new SqlParameter("@Description", SqlDbType.NText),
new SqlParameter("@Picture", SqlDbType.Image)
};
parameters[0].Value = model.CategoryName;
if (model.Description != null)
parameters[1].Value = model.Description;
else
parameters[1].Value = DBNull.Value;
parameters[2].Value = model.Picture;
return SqlHelper.GetInt(SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString(), parameters));
}
第二个问题:
如果把这个方法中间的反回类型改了 public int Add(Model.Categories model) 中间的INT 改为public Bool Add(Model.Categories model) 要怎么写。。。
第三个问题是:有没有什么书可以很好介绍一下这个类的方法反回类型不同,怎么调用,带参数和不带参数的。。使用方法。。。非常感谢
还有一个问题就是: private IList<Model.Categories> GetList(DataSet ds)
{
List<Model.Categories> l = new List<Model.Categories>();
foreach (DataRow r in ds.Tables[0].Rows)
{
l.Add(GetModel(r));
}
return l;
}
我想用这个方法写一个邦定到DATALIST上把数据显示出来要怎么写。。。。还是有更好的方法谢谢