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"..
when compiled, 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
3 1443
Which line of code that you listed is line 151?
You have three lines that reference the Textbox class and, from the error message, it would appear you have imported the windows and web assemblies that reference textbox classes. You have at least two options.
Decide whether you're building a WinForm or a Web solution and remove the other import
or
Explicitly specify whether textbox is a WinForm control or an web server control i.e. System.Forms.WebControls.Textbox or System.Windows.Form.Textbox
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).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","Sex","Area"
and my textboxes names are "id_txt","name_txt","age_txt","sex_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 = CType(e.Item.FindControl("name_txt"), 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 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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Zaidan |
last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA
code (I will consider using javascript if I have to) that does the
following, at the user command:
1- Start MS Explorer and...
|
by: abdoly |
last post by:
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update
that is the code
private void DataGrid1_UpdateCommand(object source,...
|
by: Lucas Tam |
last post by:
Hi all,
I have dyanmically created a datagrid and the cancel/update buttons do not
fire. All buttons are "edit".
Also, it seems the item indexes are off as well.
Does anyone have a tutorial...
|
by: Mark |
last post by:
I have a repetitive task where I need to edit a table in SQL Server
through a web page. Nothing fancy, just populate a datagrid and use
the commands Insert/Update/Delete/Cancel.
Is there a...
|
by: Larry Grady |
last post by:
Anyone up for a challenge?
I've been struggling with this for a few days and was hoping someone could
help me. Pouring through all the messageboards I just can't find the
solution.
We have a...
|
by: Jonathan Upright |
last post by:
Greetings to anyone who can help:
I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable
DataGrid" at the project selector screen. As you may know, it defaults
to the Microsoft...
|
by: Garry Newman |
last post by:
From what I can gather these commands are automatically
generated throught the OleDbDataAdapter wizard when
working with a one table database and from the MSDN
documnetation the values shown on...
|
by: Scott McDaniel |
last post by:
I'm using Visual Studio 2005 with the .NET 2.0.50727 framework, and we're using the standard Datagrid control bound to a
SQL Server.
We have two groups of users - "full edit" users, and "view...
|
by: Erik |
last post by:
Why isn't my update method getting called?
Pasted below is an aspx from a 1.1 application I'm working on. It has
two textboxes and a button for inserting data into the database, and a
datagrid...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |