C 資料庫幫助類SqlHelper

2021-09-06 15:03:39 字數 2708 閱讀 9248

using

system;

using

system.collections.generic;

using

system.linq;

using

system.web;

using

system.data.oledb;

using

system.data;

using

system.configuration;

using

system.data.sql;

using

system.data.sqlclient;

namespace

dal

try

else

return

false

; }

catch (exception e)

finally

}//////

執行sql語句的查詢,返回查詢的數量。異常返回-1.

/// ///

//////

///public

static

int excequery(string

sql, commandtype type, idataparameter pars)

try

else

return -1

; }

catch (exception e)

finally

}//////

執行查詢,返回乙個資料集

/// ///

//////

public

static dataset excuereturndataset(string

sql, idataparameter pars)

sqldataadapter adpter = new

sqldataadapter(com);

try

catch (exception ex)

finally

}public

static dataset excuereturndataset(string

sql,commandtype type,idataparameter pars)

sqldataadapter adpter = new

sqldataadapter(com);

try

catch (exception ex)

finally

}public

static idatareader excuereturndatareader(string

sql, idataparameter pars)

try

catch

(exception ex)

finally

}//////

執行儲存過程,返回影響的行數

/// ///

儲存過程名

///儲存過程引數

///影響的行數

///public

static

int runprocedure(string storedprocname, idataparameter parameters, out

introwsaffected)

command.parameters.add(

"@return

","").direction =parameterdirection.returnvalue;

rowsaffected =command.executenonquery();

result = (int)command.parameters["

@return

"].value;

connection.close();

return

result;}}

//////

執行儲存過程

/// ///

儲存過程名

///儲存過程引數

///dataset結果中的表名

///dataset

public

static dataset runprocedure(string storedprocname, idataparameter parameters, string

tablename)

sqldataadapter adpter = new

sqldataadapter(com);

adpter.fill(dataset, tablename);

return

dataset;}}

//////

執行查詢語句,返回dataset

/// ///

查詢語句

///dataset

public dataset query(string

sqlstring)

catch

(system.data.sqlclient.sqlexception ex)

return

ds; }}}

}

c 資料庫幫助類SqlHelper

using system using system.collections.generic using system.linq using system.web using system.data.oledb using system.data using system.configuration ...

資料庫幫助類

新建乙個類庫,專門來處理資料。我覺得這個和ef的思想是差不多的,等有時間我好好研究一下ef,以後就不再用自己寫sql了 public class sqlhelper string sql select from table sqlcommand com new sqlcommand sql,conn...

Sql Server資料庫幫助類

using system using system.collections.generic using system.linq using system.web using system.data.sqlclient using system.data using system.configurat...