sir,thank for ur response
i did as u said-
but still now also its giving error as::
--------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 137: Dim id As Integer = Int32.Parse(id_txt.Text)
Line 138: 'Dim Name1 As String = .parse(name_txt.Text)
Line 139: Dim Name1 As String = CType(e.Item.FindControl("name_txt"), Web.UI.WebControls.TextBox).Text
Line 140: 'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).Text
Line 141: Dim age1 As Integer = CType(e.Item.FindControl("age_txt"), Web.UI.WebControls.TextBox).Text
----------------------------------------------------
where the table name is "table1" and fields are "ID","Name","Age","************","Area"
and my textboxes names are "id_txt","name_txt","age_txt","************_txt","area_ txt" respectively....
And i did changes as follows:
Protected Sub datagrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.UpdateCommand
If e.CommandName = "Update" Then
Dim id As Integer = Int32.Parse(id_txt.Text)
'Dim Name1 As String = .parse(name_txt.Text)
Dim Name1 As String = CType(e.Item.FindControl("name_txt"), Web.UI.WebControls.TextBox).Text
'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).Text
Dim age1 As Integer = CType(e.Item.FindControl("age_txt"), Web.UI.WebControls.TextBox).Text
Dim sex1 As String = CType(e.Item.FindControl("************_txt"), Web.UI.WebControls.TextBox).Text
Dim area1 As String = CType(e.Item.FindControl("area_txt"), Web.UI.WebControls.TextBox).Text
Dim str As String = "UPDATE table1 SET Name='" & Name1 & "', Age = '" & age1 & "',************ = '" & sex1 & "',Area = '" & area1 & " WHERE ID = " & id
'dim str as string = "UPDATE table1 SET name = '" & name & "', description = '" & description & "', price = " & price & " WHERE id = " & id
Dim cn As String = ConfigurationSettings.AppSettings("preeconn")
Dim cmd As New SqlCommand(str, New SqlConnection(cn))
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
DataGrid1.EditItemIndex = -1
LoadData()
End If
preet
|