Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2007, 08:54 AM
Authorized User
 
Join Date: Feb 2007
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 Saving all cells in Datagrid from SQL Server

I'm new to ASP.NET and I am getting an error when I try to save a Datagrid. I am bringing in a table from SQL Server and placing it inside the datagrid which I've turned all the cells into text boxes to display the data and to edit anything at any time. The data is displayed fine and I can edit the contents but when I click on my save button to save the entire datagrid I get the following error:

Input string was not in a correct format.
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.

     The error is coming from my save function which is as follows:

          Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArgs)
         Dim myConnection As SqlConnection
         Dim myCommand As SqlCommand
         Dim dstCopy As New DataSet
         Dim strQuery As String

         myConnection = New SqlConnection("server=SQLSERVER;database=upsizedCa ndidate;Integrated Security=True;")
         myConnection.Open()
         Dim dgItem As DataGridItem
         For Each dgItem In myInfo.Items
             Dim txtCAGE As TextBox = _
             CType(dgItem.Cells(0).FindControl("txtCAGE"), TextBox)

             Dim txtName As TextBox = _
             CType(dgItem.Cells(1).FindControl("txtName"), TextBox)

             Dim txtStreet As TextBox = _
             CType(dgItem.Cells(2).FindControl("txtStreet"), TextBox)

             Dim txtCity As TextBox = _
             CType(dgItem.Cells(3).FindControl("txtCity"), TextBox)

             Dim txtState As TextBox = _
             CType(dgItem.Cells(4).FindControl("txtState"), TextBox)

             Dim txtNation As TextBox = _
             CType(dgItem.Cells(5).FindControl("txtNation"), TextBox)

             Dim txtPostal As TextBox = _
             CType(dgItem.Cells(6).FindControl("txtPostal"), TextBox)

             Dim txtPhone As TextBox = _
             CType(dgItem.Cells(7).FindControl("txtPhone"), TextBox)


             Dim item As Integer
             If txtCAGE.Text.Trim <> String.Empty Then
                 If IsNumeric(dgItem.Cells(8).Text) Then
                     item = CInt(dgItem.Cells(8).Text)
                     strQuery = "Update XH SET CAGE=" + txtCAGE.Text _
                                + ", Name='" + txtName.Text + _
                                +", Street='" + txtStreet.Text + _
                                +", City='" + txtCity.Text + _
                                +", State='" + txtState.Text + _
                                +", Nation='" + txtNation.Text + _
                               +", Postal='" + txtPostal.Text + _
                               +", Phone='" + txtPhone.Text
                 Else
                     item = 0
                     strQuery = "INSERT INTO XH (CAGE, Name, Street, City, State, Nation, Postal, Phone) VALUES('" _
                                + txtCAGE.Text + ", " + _
                                +txtName.Text + ", " + _
                                +txtStreet.Text + ", " + _
                                +txtCity.Text + ", " + _
                                +txtState.Text + ", " + _
                                +txtNation.Text + ", " + _
                                +txtPostal.Text + ", " + _
                                +txtPhone.Text + ")"
                 End If
                 myCommand = New SqlCommand(strQuery, myConnection)
                 myCommand.ExecuteNonQuery()
             End If
         Next
         myConnection.Close()
         BindData()
     End Sub

          I've tried alot of testing and nothing seems to work. I think it's something small but I can't get it. Please help! Thanks in advance.

 
Old April 23rd, 2007, 03:49 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Does your trace show the exact line number/code where the error has occured? The issue here might be with some conversion, may be with the IsNumeric function or when you convert to Integer!!

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old April 23rd, 2007, 05:07 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

IsNumeric won't throw this error, it will simply return false if you pass in a string value, however, Convert.ToInt32 will throw this error if you pass in a string value. In any case I can't give you my opinion without seeing a stack or without more information.

================================================== =========
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 planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql Server -- Datagrid BlueStag VB.NET 2002/2003 Basics 1 June 19th, 2005 09:00 AM
Saving Word File In SQL Server abdul_wasie Classic ASP Databases 0 May 20th, 2005 06:05 AM
Saving image in SQL Server 2000 ashu_from_india ADO.NET 0 February 21st, 2005 01:10 PM
Saving Excel data to SQL Server via ASP sankar Classic ASP Databases 6 February 11th, 2005 09:22 AM
Datagrid and cells haroon .NET Framework 2.0 1 October 11th, 2004 10:46 AM





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