You are on page 1of 2

Imports System.

IO
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim cn As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=
F:\WebSite2\Database1.mdb ")
Dim cmd As New OleDbCommand("select * from table1 ", cn)
Dim dr As OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
cn.Open()
' MsgBox(GridView1.Rows(e.RowIndex).Cells(1).Text)
' MsgBox(GridView1.DataSourceID.Substring(0))
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventA
rgs) Handles Button1.Click
cmd.CommandText = "insert into table1 values('" & TextBox1.Text.ToString
& "','" & TextBox2.Text.ToString & "','" & TextBox3.Text.ToString & "') "
cmd.ExecuteNonQuery()
MsgBox("save")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventA
rgs) Handles Button2.Click
Dim StrQuery As String
'dr.Read()
StrQuery = " UPDATE table1 SET name='" & TextBox2.Text.Replace("'", "' '
") & "' where MID=" & TextBox1.Text & " "
cmd.CommandText = StrQuery
cmd.ExecuteReader()
'If dr.IsClosed = False Then dr.Close()
'If (cmd.ExecuteNonQuery() > 0) Then
MsgBox("Subject Updated Successfully", vbInformation)
' Else
' MsgBox("Subject Not Updated Successfully", MsgBoxStyle.Critical, "SUBJ
ECT ERROR")
' End If

End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As Syste


m.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
AccessDataSource1.DeleteCommand = "DELETE From table1 Where MID=" & Grid
View1.Rows(e.RowIndex).Cells(0).Text
End Sub
Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System
.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
' MsgBox("Ny")
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As Syste
m.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
'' ---------- imp to know potion of index in gridview nice code
'MsgBox(e.NewValues.Item(1).ToString)
'MsgBox(e.NewValues.Item(0).ToString)
'MsgBox("ok")
'MsgBox(e.RowIndex().ToString)
'====================================

' success(code)
'====================================

'AccessDataSource1.UpdateCommand = " UPDATE table1 SET " & _


' "name='" & e.NewValues.Item(1).ToStri
ng & _
' "'where MID=" & GridView1.Rows(e.NewV
alues.Item(0)).RowIndex
'====================================
'AccessDataSource1.UpdateCommand = " UPDATE table1 SET " & _
' "name='" & e.NewValues.Item(1).ToStri
ng & _
' "'where MID=" & GridView1.Rows(e.NewV
alues.Item(0)).DataItemIndex
'====================================

'AccessDataSource1.UpdateCommand = " UPDATE table1 SET " & _


' "name='" & e.NewValues.Item(1).ToStri
ng & _
' "'where MID=" & GridView1.Rows(e.RowI
ndex).DataItemIndex

'====================================
AccessDataSource1.UpdateCommand = " UPDATE table1 SET " & _
"name='" & e.NewValues.Item(1).ToStrin
g & _
"'where MID=" & GridView1.Rows(e.RowIn
dex).ClientID

End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e


As System.EventArgs) Handles GridView1.SelectedIndexChanged

End Sub
End Class

You might also like