1、首先在web.config檔案中配置乙個與資料庫的連線connectionstrings引數就不必說是什麼意思了吧
2、採用儲存過程mvc3的訪問資料庫的通用類
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.data;
using system.data.sqlclient;
namespace shoesshop.dbuility
catch
finally
return ds;
}// 通用資料選擇**,需要有返回值result
public dataset ususelproc(string storename, string conn, string strparams, object strvalues)
else
sqlparameter rst = myad.selectcommand.parameters.add("@result", sqldbtype.int);
rst.direction = parameterdirection.output;
myad.fill(ds, "newtable");}}
catch
finally
return ds;
}// 通過資料插入與更新**
public int usuinsproc(string storename, string conn, string strparams, object strvalues)
else
sqlparameter rst = cmd.parameters.add("@result", sqldbtype.int);
rst.direction = parameterdirection.output;
cmd.prepare();
result = cmd.executenonquery();
cmd.dispose();
}catch
finally}}
return result;}}
}把這兩個地方建立好後,上層的就可以呼叫這個通用的訪問資料庫的類實現增刪改查了!
sql呼叫儲存過程
sqlconnection con new sqlconnection configurationmanager.connectionstrings easthhproductquoteconnectionstring tostring con.open sqlcommand cmd new sql...
SQL儲存過程呼叫標量值函式,儲存過程呼叫儲存過程
一 存 儲過程呼叫標量值函式 先建乙個標量值函式,如 create function dbo f num a nvarchar 50 returns nvarchar 50 asbegin declare m nvarchar 50 select m a aad return m end接下來 在儲...
SQL儲存過程游標呼叫儲存過程示例
if object id proc temp p is not null drop procedure proc temp go create procedure proc temp with recompile as select from student goexecute proc temp ...