Search

Sunday, February 28, 2010

Update or Edit the records of the database

I have use MS ACCESS database to perform updation. All i had did is take name to find the record from the database and then fired update query.

1) Import files

Imports System
Imports System.Data
Imports System.Data.OleDb

2) Declare variables and 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

3) In update button write down

Dim ssql As String = "UPDATE Stud SET Name = '" + TextBox2.Text + "' where Rollno='" + TextBox1.Text + "';"
MsgBox(ssql)
conn.Open()
Dim comm As New OleDbCommand(ssql, conn)
comm.ExecuteNonQuery()
MsgBox("record is Updated")
Response.Redirect("~/Default.aspx")
conn.Close()

No comments:

Post a Comment