Results 1 to 2 of 2

Thread: Oledb Insert into access Db

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Oledb Insert into access Db

    I have a web form coded as follows

    <form id="form1" method="post" action="default.aspx" runat="server">
    Location: <input id="txt_location" type="text" name="txt_location" /><br />
    Name: <input id="txt_name" type="text" name="txt_name" /><br />
    E-Mail: <input id="txt_email" type="text" name="txt_email" /><br />
    Telephone Number: <input id="txt_telno" type="text" name="txt_telno" /><br />

    <input id="Submit1" type="submit" value="submit" runat="server" />
    <asp:Label ID="label1" runat="server" Text="Label"></asp:Label>
    </form>

    Basically this is just four input text fields I want to pull info from and enter into an access db. The code I have on the button is as follows.

    Imports System.Data
    Imports System.Data.OleDb

    Partial Class contact_us_default
    Inherits System.Web.UI.Page



    Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
    Dim cn
    Dim str
    Dim cmd

    Dim txt_location = Request.Form("txt_location")
    Dim txt_name = Request.Form("txt_name")
    Dim txt_email = Request.Form("txt_email")
    Dim txt_telno = Request.Form("txt_telno")

    Try
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\_database\contact.mdb;")
    cn.Open()
    str = "insert into t_contact values('" & txt_location & "','" & txt_name & "','" & txt_email & "','" & txt_telno & "')"
    cmd = New OleDbCommand(str, cn)
    Catch
    End Try
    cn.Close()

    Label1.Text = "Database now updated"

    End Sub
    End Class


    When I click the button label1.text chnges to "Database now updated" so the sub definately runs but no information is entered in to the database and I do not get any errors.

    Any help would be greatly appreciated.

    Thank You.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Oledb Insert into access Db

    you never call cmd.executenonquery, which would actually run the SQL code against the database...

Posting Permissions

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



Click Here to Expand Forum to Full Width