Update Command Coding

  • Thread starter Thread starter Brian Conway
  • Start date Start date
B

Brian Conway

I have the following for an update function and I want to be able to pass in
a session variable where it is within the update statement. Does anyone
know how you can pass this session variable in here? As it is currently, it
says that it does not exist in the class or namspace. I have been able to
use it on other pages this way, but does not seem to be working here.

public static bool SaveMileageInfo(FleetMileage info)

{

int res = 0;

string sqlQuery = @"UPDATE fleet_equipments

SET ( DRIVER_FIRST_NAME,

DRIVER_LAST_NAME,

ACTUAL_MILES_QTY,

DRIVER_CUID,

AUDIT_LAST_USER_ID,

AUDIT_LAST_UPD_DT)

VALUES (?,?,?,?,?,SYSDATE)

WHERE flt_equip_id = ? ";

res = OleDbHelper.ExecuteNonQuery(sqlQuery,

CommandType.Text,

OleDbHelper.CreateParam("@pFirst_name",OleDbType.VarChar,
20,"pFirst_name",info.FirstName),

OleDbHelper.CreateParam("@pLastName",OleDbType.VarChar,
20,"pLastName",info.LastName),

OleDbHelper.CreateParam("@pCurrentOdo",OleDbType.Integer,
7,"pCurrentOdo",info.CurrentOdometerReading),

OleDbHelper.CreateParam("@pDriverCUID",OleDbType.VarChar,
8,"pDriverCUID",info.DriverCuid),

OleDbHelper.CreateParam("@pCUID",OleDbType.VarChar,
30,"pCUID",Session["CUID"]),

OleDbHelper.CreateParam("@pUnitNumber",OleDbType.VarChar,
8,"pUnitNumber",info.UnitNumber));


if(res > 0)

return true;

else

return false;

}
 
Hi Brian:

You can use the Current property of the the HttpContext class to get
to the session, i.e.

HttpContext.Current.Session

HttpContext is in the System.Web namespace, so you'll need to add a
using clause if not present. Some additional information here:
http://odetocode.com/Articles/112.aspx

Another approach to seriously consider is to pass what you need as a
parameter to the method, or add CUID as a memeber of the FleetInfo
class (if it makes sense from a OOP design point of view). The reason
being is that SaveMileageInfo then would not have to have any
dependancy on HttpContext, which is only going to be around if you are
processing a web request. Otherwise SaveMileageInfo seems like a nice
method you could use in any type of project.
 
Back
Top