Part of the sweetness in working with the .Text source is learning more about .NET from ScottW. Here is how he creates a SQL Parameter object which is reused by multiple methods, usually as part of the SqlParameter array passed to SqlHelper. I hadn't thought of creating a reusable SQLParameter object like this before.
In .Text, a staple SQL Parameter is the BlogID. First create the object.
private SqlParameter BlogIDParam
{
get
{
return SqlHelper.MakeInParam("@BlogID",SqlDbType.Int,4,Config.CurrentBlog().BlogID);
}
}
Now that its available, just add it in the SQL Parameter array list (in bold). Smart!
public int InsertCategory(LinkCategory lc)
{
SqlParameter[] p =
{
SqlHelper.MakeInParam("@Title",SqlDbType.NVarChar,150,lc.Title),
SqlHelper.MakeInParam("@Active",SqlDbType.Bit,1,lc.IsActive),
SqlHelper.MakeInParam("@CategoryType",SqlDbType.TinyInt,1,lc.CategoryType),
SqlHelper.MakeInParam("@Description",SqlDbType.NVarChar,1000,DataHelper.CheckNull(lc.Description)),
BlogIDParam,
SqlHelper.MakeInParam("@TermID",SqlDbType.Int,4,lc.TermID),
SqlHelper.MakeOutParam("@CategoryID",SqlDbType.Int,4)
};
NonQueryInt("blog_InsertCategory",p);
return (int)p[6].Value;
}
Related...
http://dbvt.com/blog/archive/2005/01/03/714.aspx | Comments