469,644 Members | 1,696 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

ExecuteNonQuery()

2
As i'm a beginner,I'm sure am missing something quite simple but i cant seem to find it or figure it out.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="vb" AutoEventWireup="True" Debug="True"%>
  2. <%@ IMPORT namespace="System.Data" %>
  3. <%@ IMPORT namespace="System.Data.OleDb" %>
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  9. <title>Insert Product, Admin Level</title>
  10. <script language="vb" runat="server">
  11. Dim connectioncw01 as OleDbConnection 
  12. Dim commandcw01 as OleDbCommand 
  13. Dim readercw01 as OleDbDataReader
  14.  
  15. Private Sub Page_Load(Sender as Object, EventArg As EventArgs)
  16.  
  17.   connectioncw01 = New OleDbConnection ("provider=microsoft.jet.oledb.4.0; data source=" + Server.MapPath(".") + "\cw01.mdb;")
  18.  
  19. End Sub
  20.  
  21. Private Sub ButtonInsert_Click(Sender as Object, EventArg As EventArgs)
  22.  
  23.   commandcw01 = new OleDbCommand("INSERT INTO Products ([ProductID], [ProductName], [Supplier], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [Reorderlevel]) VALUES (@ID, @Name, @Supplier, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @Reorderlevel  );")
  24.   commandcw01.Parameters.Add(new OleDbParameter("@ID", OleDbType.Integer))
  25.   commandcw01.Parameters("@ID").Value = TextProductID.Text
  26.   commandcw01.Parameters.Add(new OleDbParameter("@ProductName", OleDbType.Char))
  27.   commandcw01.Parameters("@ProductName").Value = TextProductName.Text
  28.   commandcw01.Parameters.Add(new OleDbParameter("@Supplier", OleDbType.Char))
  29.   commandcw01.Parameters("@Supplier").Value = TextSupplier.Text
  30.   commandcw01.Parameters.Add(new OleDbParameter("@QuantityPerUnit", OleDbType.Char))
  31.   commandcw01.Parameters("@QuantityPerUnit").Value = TextQuantityPerUnit.Text
  32.   commandcw01.Parameters.Add(new OleDbParameter("@UnitPrice", OleDbType.Integer))
  33.   commandcw01.Parameters("@UnitPrice").Value = NumberUnitPrice.Text
  34.   commandcw01.Parameters.Add(new OleDbParameter("@UnitsInStock", OleDbType.Integer))
  35.   commandcw01.Parameters("@UnitsInStock").Value = NumberUnitsInStock.Text
  36.   commandcw01.Parameters.Add(new OleDbParameter("@UnitsOnOrder", OleDbType.Integer))
  37.   commandcw01.Parameters("@UnitsOnOrder").Value =NumberUnitsOnOrder.Text
  38.   commandcw01.Parameters.Add(new OleDbParameter("@Reorderlevel", OleDbType.Integer))
  39.   commandcw01.Parameters("@Reorderlevel").Value =NumberReorderlevel.Text
  40.  
  41.   commandcw01.Connection = connectioncw01
  42.   connectioncw01.Open()
  43.   commandcw01.ExecuteNonQuery()
  44.   connectioncw01.Close() 
  45.   Server.Transfer("Admin_Main.aspx")
  46. End Sub
  47.  
  48. Private Sub ButtonBack_Click(Sender as Object, EventArg As EventArgs)
  49.   Server.Transfer("Admin_Main.aspx")
  50. End Sub
  51.  
  52. </script> 
  53. <style type="text/css">
  54.   .controlText {font-family: Verdana; font-size: 10pt; }
  55. </style>
  56.  
  57. </head>
  58. <body>
  59.   <div align="center" class="controlText">
  60.     Administration Level<br/>Adding a product</div>
  61.  
  62.   <form runat="server">
  63.     <table width="100%" cellspacing="2" cellpadding="2" border="0" class="controlText">
  64.       <tr>
  65.         <td width="39%" align="right">Product ID</td>
  66.         <td width="53%" align="left"><asp:TextBox CssClass="controlText" Width="100" ID="TextProductID" runat="server"/>
  67.           <asp:Button CssClass="controlText" Width="60" ID="ButtonInsert" Text="Add" OnClick="ButtonInsert_Click" runat="server"/>          
  68.           &nbsp;
  69.         <asp:Button CssClass="controlText" Width="60" ID="Back" Text="Back" OnClick="ButtonBack_Click" runat="server"/></td>
  70.         <td width="8%" align="left">&nbsp;        </td> 
  71.       </tr>
  72.                       <td align="right">Product Name</td> 
  73.     <td align="left"><asp:TextBox ID="TextProductName" Type="text" Size="30" Maxlength="30" runat="server"/>
  74.     <asp:RequiredFieldValidator ID="ProductNameRequired" runat="server" ControlToValidate="TextProductName"
  75.     ErrorMessage="Please list the product name" Display="dynamic"> </asp:RequiredFieldValidator>
  76.     <br />
  77.  
  78.       <tr>
  79.       <td align="right">Supplier:</td> 
  80.     <td align="left"><asp:TextBox ID="TextSupplier" Type="text" Size="30" Maxlength="30" runat="server"/>
  81.     <asp:RequiredFieldValidator ID="SupplierRequired" runat="server" ControlToValidate="TextSupplier"
  82.     ErrorMessage="Supplier Is Required" Display="dynamic"> </asp:RequiredFieldValidator>
  83.     <br />
  84.     </td>
  85.       </tr>
  86.             <td align="right">Quantity Per Unit</td> 
  87.     <td align="left"><asp:TextBox ID="TextQuantityPerUnit" Type="text" Size="30" Maxlength="30" runat="server"/>
  88.     <asp:RequiredFieldValidator ID="QuantityRequired" runat="server" ControlToValidate="TextQuantityPerUnit"
  89.     ErrorMessage="Please list the quantity" Display="dynamic"> </asp:RequiredFieldValidator>
  90.     <br />
  91.     </td>
  92.  
  93.       </tr>
  94.             <tr>
  95.       <td align="right">Unit Price ()</td> 
  96.     <td align="left"><asp:TextBox ID="NumberUnitPrice" Type="number" Size="10" Maxlength="10" runat="server" Text='00.00'/>
  97. <asp:RegularExpressionValidator ID="UnitPrice" ControlToValidate="NumberUnitPrice" runat="server" ValidationExpression="(\d{1,}\.\d{1,}|\d{1,})"> Enter a price for the product (XX.XX) </asp:RegularExpressionValidator>
  98.     <br />
  99.  
  100.             </tr>
  101.             <tr>
  102.       <td align="right">Units In Stock</td> 
  103.     <td align="left"><asp:TextBox ID="NumberUnitsInStock" Type="number" Size="10" Maxlength="10" runat="server" Text='0'/>
  104. <asp:RegularExpressionValidator ControlToValidate="NumberUnitsInStock" ValidationExpression="\d{1,}" EnableClientScript="true" ErrorMessage="Enter a range of 0 or more"
  105. runat="server" /> </asp:RegularExpressionValidator>
  106.     <br />
  107.     </td>
  108.           </tr>
  109.                   </tr>
  110.             <tr>
  111.       <td align="right">Units On Order</td> 
  112.     <td align="left"><asp:TextBox ID="NumberUnitsOnOrder" Type="number" Size="10" Maxlength="10" runat="server" Text='0'/>
  113. <asp:RegularExpressionValidator ControlToValidate="NumberUnitsOnOrder" ValidationExpression="\d{1,}" EnableClientScript="true" ErrorMessage="Enter a range of 0 or more"
  114. runat="server" /> </asp:RegularExpressionValidator>
  115.     </td>
  116.           </tr>
  117.             <tr>
  118.            <tr>
  119.       <td align="right">Reorder Level</td> 
  120.     <td align="left"><asp:TextBox ID="NumberReorderLevel" Type="number" Size="10" Maxlength="10" runat="server" Text='0'/>
  121. <asp:RegularExpressionValidator ControlToValidate="NumberReorderLevel" ValidationExpression="\d{1,}" EnableClientScript="true" ErrorMessage="Enter a range of 0 or more!"
  122. runat="server" /> </asp:RegularExpressionValidator>
  123.     <br />
  124.     </td>
  125.           </tr>
  126.             <tr>
  127.           </table>
  128.   </form>
  129. </body>
  130. </html>
Mar 14 '07 #1
0 2837

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Mark | last post: by
1 post views Thread by Mark | last post: by
5 posts views Thread by Paul Aspinall | last post: by
1 post views Thread by Matthew Louden | last post: by
reply views Thread by johnnymack0730 | last post: by
2 posts views Thread by jdb | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.