Friends here i am showing how to insert data into MS ACCESS database. I have use some textboxes to get the values ftom the users and a button to insert the data.
1) Imports the files
Imports System
Imports System.Data
Imports System.Data.OleDb
2) Declare variables an objects
Dim strConn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("~/App_Data/db2.mdb") & ";"
Dim conn As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Dim rdr As OleDb.OleDbDataReader
Dim strsql As String
Dim strins As String
3) In insert button
strins = "INSERT INTO stud VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "')"
cmd = New OleDb.OleDbCommand(strins, conn)
conn.Open()
cmd.ExecuteScalar()
conn.Close()
MsgBox("Record sudmited")
Response.Redirect("~/Default.aspx")
Thats it simple.............
Search
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment