bulletinsite.net -> -> -> . -> "Microsoft ADO.NET" -> 162

Microsoft ADO.NET - .

. Microsoft ADO.NET .: , 2003. 640 c.
ISBN 5-7502-0223-2
( ): mcrsftado2003.pdf
<< 1 .. 156 157 158 159 160 161 < 162 > 163 164 165 166 167 168 .. 260 >>

param = pc.Add("UnitPrice", OleDbType.Currency, 0, "UnitPrice") param.SourceVersion = DataRowVersion.Original
Return cmd End Function
Private Sub CreateSprocsO
Dim cmd As OleDbCommand = en.CreateCommand Dim strSQL As String
strSQL = "CREATE PROCEDURE spUpdateDetail & vbCrLf & _
(@OrderID_New int, ProductID_New int, " & vbCrLf & _ Quantity_New smallint, " & vbCrLf & _ @UnitPrice_New money, " & vbCrLf & _ i0rderID_0rig int, " & vbCrLf & _ ProduotID_0rig int, "" & vbCrLf & @Quantity_Orig smallint, " & vbCrLf & _ UnitPrice_0rig money) " & vbCrLf & _ "AS " & vbCrLf & _
"UPDATE [Order Details] & vbCrLf & _
SET OrderlD = 0rderIQ_New, " & vbCrLf & _
ProductID = ProductID,New, " & vbCrLf & _ Quantity = Quanttty_.New, " & vbCrLf & _ UnitPrice = UnitPriceJIew " & vbCrLf & _ WHERE OrderlD = 0rderID_Orig AND " & vbCrLf &_
ProductID = ProductID_0rig AND " & vbCrLf & _ Quantity = 9Quantity_0rig AND " & vbCrLf 4 _ UnitPrice = @UnitPrice_Orig" cmd.ConnnandText = strSQL cmd.ExecuteNonQuery()
strSQL = "CREATE PROCEDURE spInsertDetail ' & vbCrLf & _
(i>0rderID int, ProductID int, " & vbCrLf & _ Quantity smallint, UnitPrice money) " & vbCrLf & _ "AS " & vbCrLf & _
"INSERT INTO [Order Details] & vbCrLf & _
(OrderlD, ProductID, Quantity, UnitPrice) "& vbCrLf & _ VALUES (OrderlD, ProductID, Quantity. UnitPrice)" cmd. CommandText = strSQL cmd.ExecuteNonQueryO
istrSQL = "CREATE PROCEDURE spDeleteDetail & vbCrLf & _
(OrderlD int, ProductID int, " & vbCrLf & _ Quantity smallint, UnitPrice money) " & vbCrLf & "AS " & vbCrLf &
10 371
"DELETE FROM [Order Details] " & VbCrLf & _
WHERE OrderlD = SOrderlD and " & vbCrLf & _
ProductID = @ProductID AND " & vbCrLf & ^ Quantity = Quantity AND UnitPrice = GUnitPrice" cmd.CommandText = strSQL cmd.ExecuteNanQueryC) End Sub
Visual C# .NET
static void SubmitCriangesViaStoredProcedjresC ) {
da.UpdateCommand da.InsertCommand da.DeleteCommand da.Update(tbl);
CreateUpdateViaSPCommandO; CreateInsertViaSPCommand{) CreateOeleteViaSPCommand{)
static OleDbCommand CreateUpdateViaSPCommandO {
OleDbCommand cmd = new 01eDbCommand( "spUpdateOetail", en); cmd.CommandType = CommandType. StoredProcedure;
OleDbParameterCollection pc = cud. Parameters; pc.Add("OrderID_New", OleObType. Integer, 0, "OrderlD"); pc.Add( "ProductID_Hew", OleDbType.Integer, 0, "ProductID"); pc.Add("Quantlty_New", OleDbType. Smalllnt, 0, "Quantity"); pc.Add("UnitPrice_New", OleDbType. Currency, 0, "UnitPrice");
OleDbParameter param;
param = pc.Add("OrderID_Orig", OleDbType. Integer, 0, "OrderlD"); pB.ra.Ti. Socro9V3*"ston = DstaBowVersion. Original;
param = pc.AddC ProductlD.Orig", OleDbType. Integer, 0, "ProductID"); param, SourceVersion = DataRowVersion. Original:
param = pc.Add("QLiantity_Orig", OleDbType. Saialllnt, 0, "Quantity *); param. SourceVersion = DataRowVersion. Original;
param = pc.Addf "UnitPrioe.Orig", OleDbType.Currency, 0, "UnitPrice");
param. SourceVersion = DataRowVersion.Orioinal.
1
return cmd;
static OleDbCommand CreatelnaartVtaSPCoimncX) i
OleDbCommand cmd = new OleDbCommandf, "spInsertDetail". en); cmd.CommandType = Command type. StOfedProcedure.
OleDbParameterCollecticR pc = cmd. Parameters; pc.Add("OrderlD", OleDbType.Integer, 0, "OrderlD"); pc.Addr; "ProductID", OleDbType. Integer, 0, "ProductID");
372
III : DataSet ado.net
pc.AddrOuantity", OleDbType. Snialllnt, 0, "Quantity-); pc.Add("UnitPrice", OleDbType.Currency, 0, "UnitPrice");
return
static oledbcommand CreateDeleteViaSPCoirm,and()
{
OleDbCommand cmd = new 01eDbCommand("spDeleteDetail". cn); cmd. CommandType = CoronsandType. StoredProcedui e;
OleDbParajreterColIection pc = cnra Parameters; OleOUParameter param;
param = pc.Add("OrderID", OleDbType.Integer, 0, "OrderlD");
param.SourceVersion = OataHowVersion.Original:
param = pc.Add("'FrcductID", OleDbType. Integer, 0, "ProductID"):
param.SourceVersion = DataRowVerslon.Original;
param = pc.Add{"Quantity", OleDbType.Smalllnt, 0, "Quantity");
param.SourceVersion = OetaRowVersion.Original;
param = pc.Add("'JnitPrice", OleDbType.Currency, 0, "UnitPrice"):
param.SourceVersion = DataRowVerslon.Original;
return cmd;
static void CreataSprocsO {
OleDbCommand cmd string strSQL;
cn.CreateCommand();
strSQL = "CREAJE PROCEDURE spupdateDe tat I \n\r" +
(f0rderID_New int, roductID_New int, \n\r" + $Quantity_New small int, ''aUnitPnce_New money, \n\r" + @OrderID_0rig int, roductID_0rig int, \n\r" + @Quantity_0rig smallint, @UnitPrice_Orig money) \n\r" + "AS \n\r" +
"UPDATE [Order Details] \n\r" +
SET OrderlD = @OrderID_New, \n\r" +
ProductID = @>ProdUCtID_New, \n\r" + Quantity = #Quantity_New, \n\r" + UnitPrice = @UnitPrice_New \n\r" + WHERE OrderlD = @0rderID_0rig' AND \n\r" +
ProductID = roductID_0rig AND \n\r" + Quantity = @Quantity_0rig AND \n\r" + UnitPrice = <aUnitPrice_0rig"; cmd. Comma ndText = strSQL; cmd. ExecuteNonQueryO;
<< 1 .. 156 157 158 159 160 161 < 162 > 163 164 165 166 167 168 .. 260 >>
2009 AdsNet. .
Rambler's Top100