Results 1 to 4 of 4

Thread: Need help adding multiple records to database

  1. #1
    Join Date
    Nov 2004

    Need help adding multiple records to database

    I'm using asp.net in conjunction with the web matrix offered by MSFT to create page, basically so that anyone can add records. (Specifically new products) I'm a relative noobie and I can't seem to find my books, so I figure the next best place is the internet.

    <%@ Page Language="VB" %>
    <%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
    <script runat="server">

    ' Insert page code here

    Function MyInsertMethod(ByVal part Number As String, ByVal manufacturer As String, ByVal category As String, ByVal description As String, ByVal link As Integer) As Integer
    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an"& _
    "d Settings\Mike\My Documents\My Webs\myweb\db1.mdb"
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

    Dim queryString As String = "INSERT INTO [productlist] ([Part Number], [Manufacturer], [Category], [Descriptio"& _
    "n], [Link]) VALUES (@Part Number, @Manufacturer, @Category, @Description, @Link)"& _
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dbParam_part Number As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_part Number.ParameterName = "@Part Number"
    dbParam_part Number.Value = part Number
    dbParam_part Number.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_part Number)
    Dim dbParam_manufacturer As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_manufacturer.ParameterName = "@Manufacturer"
    dbParam_manufacturer.Value = manufacturer
    dbParam_manufacturer.DbType = System.Data.DbType.String
    Dim dbParam_category As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_category.ParameterName = "@Category"
    dbParam_category.Value = category
    dbParam_category.DbType = System.Data.DbType.String
    Dim dbParam_description As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_description.ParameterName = "@Description"
    dbParam_description.Value = description
    dbParam_description.DbType = System.Data.DbType.String
    Dim dbParam_link As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
    dbParam_link.ParameterName = "@Link"
    dbParam_link.Value = link
    dbParam_link.DbType = System.Data.DbType.Int32

    Dim rowsAffected As Integer = 0
    rowsAffected = dbCommand.ExecuteNonQuery
    End Try

    Return rowsAffected
    End Function

    <body text="black" vlink="blue" link="blue">
    <form runat="server">
    Enter New Products into the Database:
    Manufacturer's Part Number:
    <asp:TextBox id="Partnumb" runat="server"></asp:TextBox>
    &nbsp;(The product&nbsp;number that the manufaturer uses)
    Manufacturer Name:
    <asp:TextBox id="Manufact" runat="server"></asp:TextBox>
    &nbsp;(Devil Biss, Sherwin Williams, etc)
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
    &nbsp;(Abrasives, Paint, Paint Guns)
    Description of Product:<br />
    <asp:TextBox id="Proddesc" runat="server" Width="461px" Height="77px"></asp:TextBox>
    Link for product:
    <asp:TextBox id="Link" runat="server"></asp:TextBox>
    &nbsp;(<a disabled="disabled" href="http://www.sherwin-williams.com/arew_awe.pdf">http://www.sherwin-williams.com/arew_awe.pdf</a>)<br />
    <p align="center">
    <asp:Button id="Submit" runat="server" Text="Submit To Product Database"></asp:Button>
    <!-- Insert content here -->

    What do I need to do to add the values to that database? Any ideas?

  2. #2
    Join Date
    Jan 2004
    Melbourne, Australia
    This is best sui ted in the .NET forum. I will move it there for you.

  3. #3
    Join Date
    Nov 2004


    Thanks.. wherever will help end my headache

  4. #4
    Join Date
    Nov 2004
    Put this Sub in your code above the MyInsertMethod and then follow what is below.

    Sub Button_Click(sender as Object, e as EventArgs)

    MyInsertMethod(Partnumb.Text, Manufact.Text, TextBox1.Text, Proddesc.Text, Link.Text)

    End Sub

    Then you need to make sure that in your Button at the Submit part that you put the OnClick to point to the Button_Click sub.

    <asp:Button id="Submit" runat="server" Text="Submit To Product Database" OnClick="Button_Click"></asp:Button>

    That should take care of that. Make sure that your partnumber parameter does not have a space in the name.

    Ben Miller
    All responses are provided AS IS and do not necessarily reflect my employers views.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles