General discussion

Locked

update,delete,cancel buttons in datagrid using vb.net....

By preethams_venkatesh4 ·
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

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 = 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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Ambiguous TextBox

by ntaylor1 In reply to update,delete,cancel butt ...

Looks like you are importing System.Web.UI.WebControls and System.Windows.Forms into your CodeBehind where by the Control TextBox exists in Both Namespaces (Ambiguous). As a Web Project I cant see why you would want WinForms Controls... If for whatever reason you do need both of these imported namespaces you could try changing your casts to CType(....,System.Web.UI.WebControls.TextBox) this way you are explicitly telling the compiler which TextBox to use...

Good Luck!

Happy Debugging

Collapse -

Solution Of Typecasting

by ranjit12071982 In reply to update,delete,cancel butt ...

if you have already added the reference of windows.form then this error might occur. So this is better to cast the textbox with fully qualified source class.
So, Insted of
Name1 = CType(e.Item.FindControl("Name1"), Textbox).text
you shoud use
Name1 = CType(e.Item.FindControl("Name1"), System.Web.UI.WebControls.TextBox).text

I hope this will be the reason.
Happy Coding.

Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums