how to connect asp.net with MS-access and also how to pass data to

Discussion in 'ASP .Net Datagrid Control' started by Jack, Sep 14, 2006.

  1. Jack

    Jack Guest

    hI,

    Anyone here know how to connect asp.net with MS-access and also how to pass
    data to a table?

    The following is the code which I have but unfortunately its not working..
    Public Connectionstring As String =
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
    C:\Inetpub\wwwroot\Dee\ASPdotnet\currt.mdb;Persist Security Info=False;"
    Public con As New OleDbConnection(Connectionstring)


    Dim strSelect As String
    strSelect = "Insert Into UserDetails1 (Username) Values
    (@DetailsUser)"
    Dim cmd As New OleDbCommand(strSelect, con)
    Dim added As Integer
    cmd.Parameters.Add("@DetailsUser", txtUserDetails.Text)

    Try
    con.Open()
    cmd.ExecuteNonQuery()
    Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")

    con.Close()
    Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")
    Catch
    con.Close()
    End Try



    Thanks in advance
    Jack
    Jack, Sep 14, 2006
    #1
    1. Advertising

  2. Hi Jack,

    Here's some code that seems to do what you want.

    Let us know if it helps?

    Ken
    Microsoft MVP [ASP.NET]

    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Button1_Click _
    (ByVal sender As Object, ByVal e As System.EventArgs)
    Dim Connectionstring As String = _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & _
    "C:\ASPNETWeb\App_Data\currt.mdb;Persist Security Info=False;"
    Dim con As New Data.OleDb.OleDbConnection _
    (Connectionstring)

    Dim strSelect As String
    strSelect = "Insert Into UserDetails1 (Username) Values " & _
    "(@DetailsUser)"
    Dim cmd As New Data.OleDb.OleDbCommand(strSelect, con)
    Dim pms As Data.OleDb.OleDbParameterCollection
    pms = cmd.Parameters
    pms.Add("@DetailsUser", Data.OleDb.OleDbType.VarChar, 50)
    pms("@DetailsUser").Value = Server.HtmlEncode(txtUserDetails.Text)
    Try
    con.Open()
    cmd.ExecuteNonQuery()
    Response.Write _
    ("Updated Successfully!<p> </p><p> </p><p> </p>")
    Catch exc As Exception
    Response.Write("Problem: " & exc.Message & _
    "<p> </p><p> </p><p> </p>")
    Finally
    con.Close()
    End Try
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Insert into Access Database</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:textbox id="txtUserDetails" runat="server"></asp:textbox><br />
    <br />
    <asp:button id="Button1" runat="server" onclick="Button1_Click"
    text="Insert" />&nbsp;</div>

    </form>
    </body>
    </html>



    "Jack" <> wrote in message
    news:...
    > hI,
    >
    > Anyone here know how to connect asp.net with MS-access and also how to
    > pass
    > data to a table?
    >
    > The following is the code which I have but unfortunately its not working..
    > Public Connectionstring As String =
    > "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =
    > C:\Inetpub\wwwroot\Dee\ASPdotnet\currt.mdb;Persist Security Info=False;"
    > Public con As New OleDbConnection(Connectionstring)
    >
    >
    > Dim strSelect As String
    > strSelect = "Insert Into UserDetails1 (Username) Values
    > (@DetailsUser)"
    > Dim cmd As New OleDbCommand(strSelect, con)
    > Dim added As Integer
    > cmd.Parameters.Add("@DetailsUser", txtUserDetails.Text)
    >
    > Try
    > con.Open()
    > cmd.ExecuteNonQuery()
    > Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")
    >
    > con.Close()
    > Response.Write("Updated Successfully!<p> </p><p> </p><p> </p>")
    > Catch
    > con.Close()
    > End Try
    >
    >
    >
    > Thanks in advance
    > Jack
    >
    Ken Cox [Microsoft MVP], Sep 18, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bit Byte
    Replies:
    1
    Views:
    823
    Teemu Keiski
    Jan 28, 2007
  2. Replies:
    3
    Views:
    900
    Frederick Gotham
    Nov 30, 2006
  3. Mohsen Pahlevanzadeh

    Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    3
    Views:
    146
    Mohsen Pahlevanzadeh
    Sep 18, 2013
  4. Mohsen Pahlevanzadeh

    Re: Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    0
    Views:
    111
    Mohsen Pahlevanzadeh
    Sep 17, 2013
  5. Oscar Benjamin

    Re: Qt connect and first connect or unicode

    Oscar Benjamin, Sep 17, 2013, in forum: Python
    Replies:
    0
    Views:
    110
    Oscar Benjamin
    Sep 17, 2013
Loading...

Share This Page