MS Access connection

Discussion in 'ASP .Net' started by sjsean, Jan 25, 2010.

  1. sjsean

    sjsean Guest

    I've been trying for awhile to get the code below to "work" but alas
    nothing seems to update the table in the database.

    I have a button on a page which when clicked should insert a new
    record into the database...all of this just to test that I am doing
    correctly (or at this point doing something wrong). Any suggestions
    on why a record never gets inserted?


    <%@ Page Language="VB" AutoEventWireup="false"
    CodeFile="Default2.aspx.vb" Inherits="Default2" %>


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

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <asp:Button ID="Button1" runat="server" Text="Button" />

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

    -------------------------------------------------------------------------

    Imports System.Data.OleDb

    Partial Class Default2

    Inherits System.Web.UI.Page



    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Dim dbconn
    Dim sql_statement
    Dim dbcomm
    Dim sqlsrcacc
    dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.
    4.0;data source=" & Server.MapPath("App_data/testdatabase.mdb"))
    dbconn.Open()
    sql_statement = "Insert into tbl_photo (photo_name) values
    ('1')"
    dbcomm = New OleDbCommand(sql_statement, dbconn)
    dbconn.close()

    End Sub
    End Class
     
    sjsean, Jan 25, 2010
    #1
    1. Advertising

  2. On Jan 25, 11:38 pm, sjsean <> wrote:
    > I've been trying for awhile to get the code below to "work" but alas
    > nothing seems to update the table in the database.
    >
    > I have a button on a page which when clicked should insert a new
    > record into the database...all of this just to test that I am doing
    > correctly (or at this point doing something wrong).  Any suggestions
    > on why a record never gets inserted?
    >
    > <%@ Page Language="VB" AutoEventWireup="false"
    > CodeFile="Default2.aspx.vb" Inherits="Default2" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head runat="server">
    >     <title></title>
    > </head>
    > <body>
    >     <form id="form1" runat="server">
    >     <div>
    >
    >         <asp:Button ID="Button1" runat="server" Text="Button" />
    >
    >     </div>
    >     </form>
    > </body>
    > </html>
    >
    > -------------------------------------------------------------------------
    >
    > Imports System.Data.OleDb
    >
    > Partial Class Default2
    >
    >     Inherits System.Web.UI.Page
    >
    >     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >         Dim dbconn
    >         Dim sql_statement
    >         Dim dbcomm
    >         Dim sqlsrcacc
    >         dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.
    > 4.0;data source=" & Server.MapPath("App_data/testdatabase.mdb"))
    >         dbconn.Open()
    >         sql_statement = "Insert into tbl_photo (photo_name) values
    > ('1')"
    >         dbcomm = New OleDbCommand(sql_statement, dbconn)
    >         dbconn.close()
    >
    >     End Sub
    > End Class


    dbcomm.ExecuteNonQuery is missing there
     
    Alexey Smirnov, Jan 25, 2010
    #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. Mythran
    Replies:
    5
    Views:
    4,952
    Mythran
    Oct 5, 2005
  2. Dave Johnson

    Using Connection Class VS Connection Module

    Dave Johnson, Dec 9, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    634
    Dave Johnson
    Dec 11, 2005
  3. Linus Nikander
    Replies:
    5
    Views:
    545
  4. Replies:
    3
    Views:
    40,284
    Roedy Green
    Nov 16, 2005
  5. R
    Replies:
    1
    Views:
    574
Loading...

Share This Page