| | |
update,delete,cancel buttons for datagrid
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
can anybody plz tell m -whats the error in the code for update button in datagrid-where table name is "table1"its has fields "ID","Name","Age","Sex","Area"..
in the code its giving error has::
----------------------
c:\inetpub\wwwroot\sampleprj1\WebForm1.aspx.vb(151): 'Textbox' is ambiguous, imported from the namespaces or types 'System.Web.UI.WebControls, System.Windows.Forms'.
------------------------------
The code is as follows
ProtectedSub datagrid1_UpdateCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
If e.CommandName = "Update" Then
Dim id As Integer = e.Item.Cells(0).Text
Dim Name1 As String
Name1 = CType(e.Item.FindControl("Name1"), Textbox).text
Dim age1 As Integer = CType(e.Item.FindControl("Age"), Textbox).text
Dim sex1 As String = CType(e.Item.FindControl("Sex"), Textbox).text
Dim area1 As String = CType(e.Item.FindControl("Area"), Textbox).text
Dim str As String = "UPDATE table1 SET Name1='" & Name1 & "', age1 = '" & age1 & "',sex1 = '" & sex1 & "',area1 = '" & area1 & " 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
End Sub
-----------
plz its very urgent,help mm
in the code its giving error has::
----------------------
c:\inetpub\wwwroot\sampleprj1\WebForm1.aspx.vb(151): 'Textbox' is ambiguous, imported from the namespaces or types 'System.Web.UI.WebControls, System.Windows.Forms'.
------------------------------
The code is as follows
ProtectedSub datagrid1_UpdateCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
If e.CommandName = "Update" Then
Dim id As Integer = e.Item.Cells(0).Text
Dim Name1 As String
Name1 = CType(e.Item.FindControl("Name1"), Textbox).text
Dim age1 As Integer = CType(e.Item.FindControl("Age"), Textbox).text
Dim sex1 As String = CType(e.Item.FindControl("Sex"), Textbox).text
Dim area1 As String = CType(e.Item.FindControl("Area"), Textbox).text
Dim str As String = "UPDATE table1 SET Name1='" & Name1 & "', age1 = '" & age1 & "',sex1 = '" & sex1 & "',area1 = '" & area1 & " 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
End Sub
-----------
plz its very urgent,help mm
I think there is ambiguity of the type of textbox , u need to decide whether it is Windows textbox or web control text box
Try this
Or
i hope this will help u
Try this
VB.NET Syntax (Toggle Plain Text)
Dim age1 As Integer = CType(e.Item.FindControl("Age"), Web.UI.WebControls.TextBox).text
VB.NET Syntax (Toggle Plain Text)
Dim age1 As Integer = CType(e.Item.FindControl("Age"), Windows.Forms.TextBox).text
i hope this will help u
"give only what u willing to receive "
sir,thank for ur response
i did changes 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).TextLine 140: 'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).TextLine 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","Sex","Area"
and my textboxes names are "id_txt","name_txt","age_txt","sex_txt","area_txt" respectively....
And i did changes as follows:
ProtectedSub datagrid1_UpdateCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
If e.CommandName = "Update" Then
Dim id AsInteger = 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("sex_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 & "',Sex = '" & 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
-----------
sir,plz help mmmm its very urgent
i did changes 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).TextLine 140: 'Dim Name1 As String = CType(e.Item.FindControl("Name"), Web.UI.WebControls.TextBox).TextLine 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","Sex","Area"
and my textboxes names are "id_txt","name_txt","age_txt","sex_txt","area_txt" respectively....
And i did changes as follows:
ProtectedSub datagrid1_UpdateCommand(ByVal source AsObject, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
If e.CommandName = "Update" Then
Dim id AsInteger = 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("sex_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 & "',Sex = '" & 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
-----------
sir,plz help mmmm its very urgent
![]() |
Similar Threads
- how to write code for update,delete,cancel buttons in datagrid using vb.net only..plz (IT Professionals' Lounge)
- Windows Mobile & Datagrid (VB.NET)
- How to delete/cancel print job already in queue (Visual Basic 4 / 5 / 6)
- ASP add, update and delete (ASP)
- The Datagrid: How does one fill text boxes in edit mode with their original content? (ASP.NET)
- binding radio buttons (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: encrypt and decrypt query string
- Next Thread: date and time in file name
Views: 7894 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial shutdown soap sorting survey syntax table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





