Wednesday, October 18, 2006
Code Sample: Passing object[] to SqlHelper
Apologies for the lost indentation: that I can't use CopyAsHtml well at blogger.com is probably the biggest reason that I should be blogging with Subtext.
// Call SqlHelper with the 'params SqlParameter[] overload'
public void GetWithSqlParams(SystemUser aUser)
{
SqlParameter idParam = new SqlParameter("@id", aUser.Id);
SqlParameter nameParam = new SqlParameter("@name", aUser.Name);
SqlParameter emailParam = new SqlParameter("@name", aUser.Email);
SqlParameter loginParam = new SqlParameter("@name", aUser.LastLogin);
SqlParameter logoutParam = new SqlParameter("@name", aUser.LastLogOut);
SqlHelper.ExecuteNonQuery(
Settings.ConnectionString, CommandType.StoredProcedure, "User_Update",
idParam,
nameParam,
emailParam,
loginParam,
logoutParam);
}
// Call SqlHelper with the 'params object[] overload'
public void GetWithObjects(SystemUser aUser)
{
SqlHelper.ExecuteNonQuery(
Settings.ConnectionString, "User_Update",
aUser.Id,
aUser.Email,
aUser.Name,
aUser.LastLogin,
aUser.LastLogOut);
}
// Which is semantically identical with:
public void GetWithObjectArray(SystemUser aUser)
{
SqlHelper.ExecuteNonQuery(
Settings.ConnectionString, "User_Update",
new object[]
{
aUser.Id,
aUser.Email,
aUser.Name,
aUser.LastLogin,
aUser.LastLogOut
});
}
<< Home