資料庫幫助類

2022-03-28 17:01:50 字數 1008 閱讀 2158

新建乙個類庫,專門來處理資料。我覺得這個和ef的思想是差不多的,等有時間我好好研究一下ef,以後就不再用自己寫sql了

public

class

sqlhelper

//string sql = "select * from table";

sqlcommand com = new

sqlcommand(sql, conn);

sqldataadapter adapter = new

sqldataadapter(com);

adapter.fill(dt);

}return

dt; }

//判斷登入資訊的

public

string sqlquery(string id, string

pword)

sqlcommand com = new

sqlcommand(sql, conn);

sqlparameter parameters =;

parameters[

0].value =id;

parameters[

1].value =pword;

com.parameters.addrange(parameters);

if (com.executescalar()!=null

)

else

}else

}

}//增刪改

public

int excute(string

sql)

//string sql = "select * from table";

sqlcommand com = new

sqlcommand(sql, conn);

int result =com.executenonquery();

return

result;}}

}

Sql Server資料庫幫助類

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

Sql Server 資料庫幫助類

注 資料庫操作幫助封裝類,簡單易用,減少 冗餘 資料庫鏈結 也可配置在web.config 檔案中 public static readonly string connectionstring server 資料庫鏈結 uid 賬號 pwd 密碼 database 資料庫名 執行乙個不需要返回值的s...

Sql Server 資料庫幫助類

using system using system.text using system.data using system.data.common namespace data.core 關聯式資料庫連線字串 public static string connectionstring if debu...