473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 2886

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

Similar topics

2
by: Mark | last post by:
Hi, I have a sqlCommand object that I use to execute an SQL statement. I thought I could use the ExecuteNonQuery to test for the number of rows returned by the sql command but it does not seem to...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
5
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper...
1
by: Matthew Louden | last post by:
I just tried to create a simple ASP.NET application to add record to the SQL Server database. However, it has run time error on Line 88: objCommand.ExecuteNonQuery() Any ideas?? Please help!!...
0
by: johnnymack0730 | last post by:
Hello - I am currently working on an asp.net application that needs to be able to update an access table using ExecuteNonQuery method. I have all the code setup, it runs, there are no errors...
4
by: MDW | last post by:
Hey all. I'm confused. I'm trying to add a single record into an Access 2000 database using ASP.Net. Here is the code: objConn = New OleDbConnection(strConnect) objConn.Open objCommand =...
2
by: jdb | last post by:
Hi, I am adding a record to the database using an ExecuteNonQuery, which adds without problem. Now after the record is added I run a method passing in some info as well as the curretnly opened...
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.