7 Years
Discussion Span
Last Post by samacoba

It contains the HTML and VB.net code that makes up thepage. It's important to note that the VB.Net code is placed within the page_load event. This just means that every time the page is requested the page_load event is raised or run and the code we've written is executed. The C# equivalent must be similar too...

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.Oledb" %>

<!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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Connection As OledbConnection
        Connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & _
                                     "Data Source=C:\Inetpub\wwwroot\code\Customers.mdb")
        Dim Command As OleDbCommand
        Command = New OleDbCommand("INSERT INTO tblCustomers(FirstName, LastName)" & _
        " VALUES ('Michael', 'Wall')", Connection)
        Label1.Text="Record Inserted"
    End Sub

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Insert Record into MS Access Database</title>
    <form id="form1" runat="server">
        <asp:label ID=label1 runat="server" />

Edited by s_sridhar: n/a


i am using access db plz tell me how to insert data from database. m using visual studio 2010.

Firstly, tell us the name of database product you are using. Secondly, learn the ADO.NET class library through this library you can perform any database actions.


Thanx for your help.
Sir,i have a problem that how i can insert through web application means by using textbox buttons etc.
If you can plz provide me with sample coding.


Try this code,it inserts one parameter(txtName.Text) into table"tblTble",for all paramemters(OleDbProvider uses "?" to represent SQL Prameters)the analogy is the same,also Note this goes under the Button(Insert) click event...Try reading more about the DataAdapter Object from MSDN website...Hope this helps you

string myConstr = "@YourConnectionString;
string InsertQrt ="Insert Into tblTable(Name) Values(?)";
OleDbConnection myConnection = new OleDbConnection(myConstr);
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
myAdapter.InsertCommand = new OleDbCommand(InsertQry, myConnection);
myAdapter.InsertCommand.Parameters.Add(new OleDbParameter("?",txtName.Text));

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.