Code:
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As OleDbConnection 'Only need to create OleDbConnection type reference
Dim com As OleDbCommand 'Only need to create OleDbCommand type reference
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack = True Then
Reset()
End If
End Sub
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim sqlString, STID, STNAME, AGE, ADMNO, FNAME, MNAME, BATCH, ADDRESS, PHNO, MOBNO, EMAIL As String
STID = TextBox1.Text
STNAME = TextBox2.Text
AGE = TextBox3.Text
ADMNO = TextBox4.Text
FNAME = TextBox5.Text
MNAME = TextBox6.Text
BATCH = TextBox7.Text
ADDRESS = TextBox8.Text
PHNO = TextBox9.Text
MOBNO = TextBox10.Text
EMAIL = TextBox13.Text
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Varsha\My music\Visual Studio 2005\WebSites\PSA\App_Data\student.mdb")
con.Open()
sqlString = "insert into Table1 values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox13.Text & "')"
com = New OleDbCommand(sqlString, con)
com.ExecuteNonQuery()
MsgBox("Data is successfully entered")
con.Close()
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim checkID As String = "select id_field from table1 where id_field='" + TextBox1.Text + "'"
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Varsha\My music\Visual Studio 2005\WebSites\PSA\App_Data\student.mdb")
con.Open()
com = New OleDbCommand(checkID, con)
Dim result As SByte = com.ExecuteNonQuery()
con.Close()
If result > 0 Then
MsgBox("ID Already Exists!")
' Code here to disable submit button
Else
'code here to enable submit button
End If
End Sub
End Class

