Better use of SQLHELPER classes

zhaozj2021-02-16  111

The most commonly used data operation is encapsulated in the SQLHELPER class in the Data Access Application Block provided by Microsoft. I originally written this for a method of returning a DataSet:

public

Dataset getDepartmentMemberlist (

int

DepartmentID)

{Try {string sql = "OA_Department_GetDepartment_Members"; string conn = ConfigurationSettings.AppSettings [ "strConnection"]; SqlParameter [] p = {SqlHelper.MakeInParam ( "@ departmentID", SqlDbType.Int, 4, departmentID)}; DataSet ds = SQLHELPER.EXECUTEDATASET (CONN, CommandType.StoredProcedure) (SQL, P); Return DS;} catch (system.data.sqlclient.sqlexception ER) {throw new exception (Er.MESSAGE);}

Now I am writing like this:

//

Connection string

Private

String

_ConnectionString

=

ConfigurationSettings.AppSettings [

"

StrConnection

"

];

public

String

Connectionstring

{Get {return this._connectionstring;} set {this._connectionstring = value;}}

public

Dataset getNewStoIndexpage

int

NewstypeID)

{Return getDataSet ("yzb_getnewstoindexpage", getnewstoIndexpage_parameters (newstypeid);}

//

Set stored procedure parameters

Private

Sqlparameter [] getNewStoIndexpage_Parameters

int

NewstypeID)

{SQLParameter [] P = {SQLHELPER.MAKEINPARAM ("@ newstypeid", sqldbtype.int, 4, newstypeid)}; return p;}

//

Here, I really call SQLHELPER.

Private

Dataset getDataSet

String

SQL,

Params

Sqlparameter [] P)

{Return Sqlhelper.executed, CommandType.StoredProcedure, SQL, P);

The code is more flexible, safer: P

转载请注明原文地址:https://www.9cbs.com/read-13463.html

New Post(0)