Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 26th, 2007, 01:18 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default Editing Datagrid

Hi Everyone,
I have brought in a table from SQL Server into ASP.NET through Datagrid and have turned all fields into textboxes so the user can edit any textbox and click save once. However when the save button is clicked then all textboxes are changed to the value which is in the last row. Here is the code for my save button:

Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArgs)

Dim myCommand As SqlCommand
Dim dstCopy As New DataSet
Dim strQuery As String

objConnection = New SqlConnection("server=SQLSERVER;database=upsizedCa ndidate;Integrated Security=True;")
objConnection.Open()

Dim dgItem As DataGridItem
For Each dgItem In myInfo.Items
Dim txtNewColumn1 As TextBox = CType(dgItem.Cells(0).FindControl("txtNewCol1"), TextBox)

Dim txtNewColumn2 As TextBox = CType(dgItem.Cells(1).FindControl("txtNewCol2"), TextBox)

strQuery = String.Format("update ToddsTable3 set NewCol1= '" + txtNewColumn1.Text + "',NewCol2='" + txtNewColumn2.Text + "'")

myCommand = New SqlCommand(strQuery, objConnection)
myCommand.ExecuteNonQuery()

Next

DataBind()
myInfo.DataBind()
objConnection.Close()
myInfo.EditItemIndex = -1


BindGrid()
End Sub

I have no idea what could be wrong and this has been driving me crazy. could anyone please help me? Thanks in advance

Reply With Quote
  #2 (permalink)  
Old April 26th, 2007, 01:29 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there... first of all your update doesn't have any where clause.. so it's updating all the table!

maybe there is a problem with the data you are obtaining??

also the grid has this functionality built in.. so you don't have to write any code to do this..


HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
Reply With Quote
  #3 (permalink)  
Old April 26th, 2007, 02:03 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

Cool, I almost have it worked out. Thank you so much for helping me out!

Reply With Quote
  #4 (permalink)  
Old April 26th, 2007, 02:42 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

Hi again, sorry to bother you but I have just one more bug that I cannot figure out. When I click save, it gives me the following error:
Exception Details: System.Data.SqlClient.SqlException: Invalid column name '__Page'.

The debug says it is occurring at the line:
myCommand.ExecuteNonQuery()


I've checked everywhere and nothing resembles "Page". any thoughts?

Reply With Quote
  #5 (permalink)  
Old April 26th, 2007, 02:53 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

i don't know.. did you change the SQL?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
Reply With Quote
  #6 (permalink)  
Old April 26th, 2007, 03:06 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

Hi Gonzalo,
     I switched all instances of ID to resemble the other two columns and it worked perfectly. Thanks for helping me! You've made my weekend!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Editing Problem gaurav_jain2403 .NET Framework 1.x 2 December 9th, 2006 04:33 AM
Editing in DataGrid abdul_owiusa ASP.NET 1.0 and 1.1 Professional 0 May 1st, 2006 07:56 AM
Problem with Datagrid Editing pramesh_it ASP.NET 1.0 and 1.1 Basics 0 April 17th, 2006 09:58 AM
Multiplerecord editing in Datagrid vids ASP.NET 1.x and 2.0 Application Design 0 March 10th, 2005 11:41 AM
Editing in Datagrid with ASP.NET rotsey General .NET 0 October 22nd, 2004 01:38 AM



All times are GMT -4. The time now is 09:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.