MS Access connection

  • Thread starter Thread starter sjsean
  • Start date Start date
S

sjsean

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
 
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
 
Back
Top