I am using a datagrid for showing values from database.I have code for showing and deleting records as follows
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Me.IsPostBack = False Then
Dim myController As New controller("select *from Missing", "Missing")
Dim ds As DataSet = myController.getdataset()
bindgrid(ds)
End If
End Sub
Public Sub bindgrid(ByVal ds As DataSet)
DataGrid1.DataSource = ds.Tables("Missing")
Me.DataBind()
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim constring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\WebProject\myDb.mdb"
Dim f, l As String
f = CType(e.Item.FindControl("FirstName"), TextBox).Text
l = CType(e.Item.FindControl("LastName"), TextBox).Text
Dim str As String = "Delete from Missing where (FirstName='" & f & "') and (LastName='" & l & "')"
Dim con As New OleDbConnection(constring)
Dim cmd As New OleDbCommand(str, con)
Try
con.Open()
Dim x As Integer
x = cmd.ExecuteNonQuery
Catch ex As Exception
Finally
If Not con Is Nothing Then
con.Close()
End If
End Try
DataGrid1.EditItemIndex = -1
Dim myController As New controller("select *from Missing", "Missing")
Dim ds As DataSet = myController.getdataset
bindgrid(ds)
'Label1.Text = myController.exc.Message
End Sub
It gives me error at bold line.
The error is as follows
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
is there any new way to delete value?
Pls help me.