Insert data to OleDbConnection using SQL (VB.net) : Insert OleDbConnection « ADO.net Database « ASP.Net






Insert data to OleDbConnection using SQL (VB.net)

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim DBConn as OleDbConnection
    Dim DBAdd As New OleDbCommand
    DBConn = New OleDbConnection( _
        "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
        & "DATA SOURCE=" _
        & Server.MapPath("EmployeeDatabase.mdb;"))
    DBAdd.CommandText = "Insert Into Employee (" _
        & "LastName, FirstName ) values (" _
        & "'" & Replace(txtLastName.Text, "'", "''") _
        & "', " _
        & "'" & Replace(txtFirstName.Text, "'", "''") _
        & "')"
    DBAdd.Connection = DBConn
    DBAdd.Connection.Open
    DBAdd.ExecuteNonQuery()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Adding Access Data</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR>
Last Name:
<BR>
<asp:textbox
    id="txtLastName"
    runat="Server"
/>
<BR>
First Name:
<BR>
<asp:textbox
    id="txtFirstName"
    runat="Server"
/>
<BR><BR>
<asp:button 
    id="butOK"
    text="  OK  "
    onclick="SubmitBtn_Click" 
    runat="server"
/>  
</form>
</BODY>
</HTML>
           
       








EmployeeDatabase.zip( 10 k)

Related examples in the same category

1.Generate SQL insert command (VB.net)
2.Insert data to database using SQL (C#)