Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 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 October 18th, 2005, 10:32 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exception Entered

Hi,

I'm having some problems trying to use a datareader to bind to a datagrid. The following is my code:

 Inherits System.Web.UI.Page
    Dim conn As SqlClient.SqlConnection

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New SqlClient.SqlConnection(Application("strConnect"))
        If Not Page.IsPostBack Then
            Dim comm As New SqlClient.SqlCommand("Select a.tdesc, a.aba, a.acctno, a.expense, b.amount from Cms_TymetrixDetail a, Cms_TymetrixFtp b where a.tdesc = b.payee order by a.aba asc", conn)
            Dim dr As SqlClient.SqlDataReader
            Try
                conn.Open()
                dr = comm.ExecuteReader()
                dgTyVer.DataSource = dr
                dgTyVer.DataBind()
            Catch
                Throw New ArgumentException("Exception Entered")
            Finally
                dr.Close()
                conn.Close()
            End Try
        End If

And here is my error:

Exception Entered
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.ArgumentException: Exception Entered

Source Error:


Line 35: dgTyVer.DataBind()
Line 36: Catch
Line 37: Throw New ArgumentException("Exception Entered")
Line 38: Finally
Line 39: dr.Close()


Source File: C:\Inetpub\wwwroot\CPS3\TyVerList.aspx.vb Line: 37

Stack Trace:


[ArgumentException: Exception Entered]
   CPS.TyVerList.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\CPS3\TyVerList.aspx.vb:37
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750

I'm not sure what the problem is here. I checked my grid and matched the datafield names with the names I've chosen in my sql statement. However, I do have a column that is not being used by the datareader and therefore it is not bound. I doubt that is the problem because I took it out and still got the same problem. What am I doing wrong? Can someone please help me? Thank you.




 
Old October 18th, 2005, 10:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

To see the real error, you shouldn't Catch anything, or if you do want to use a Catch block, use only Throw (not Throw Ex or Throw New Exception)

By throwing your own error, you loose the call stack and information about the original error.
Remote your code block and you'll see an error message indicating the real error.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 18th, 2005, 11:08 AM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for responding so quickly. I have solved the problem. However, I had a question regarding my grid. As I mentioned before, I have an additional column that is not being used by the datasource. That column is called difference and is the difference between a.expense and b.amount for each record. Is there a way to display that difference for each record in the grid?

I was thinking of using a for i = 0 to i - 1 loop which loops through the total count of the grid. But, I doubt it'll be able to display all of them especially if the grid consists of mutiple pages. Can someone please tell me what I can do? Thanks again.

 
Old October 18th, 2005, 12:09 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have resolved this problem as well.

 
Old October 18th, 2005, 12:12 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Great. For the benefits of the archive of this forum, would you mind telling us how you fixed it?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 Sum Value in TextBoxes when Entered Instatly prasanna.nadgir ASP.NET 1.0 and 1.1 Basics 5 August 27th, 2007 04:31 AM
retaining the last data that was entered Calibus Classic ASP Databases 4 October 14th, 2004 03:31 PM
change Entered key melvik C# 0 June 19th, 2004 09:42 AM
DATE VALUE DISPLAYED NOT AS ENTERED hosefo81 PHP Databases 2 November 4th, 2003 10:36 PM
Maintain entered data sporkman43 Classic ASP Basics 2 October 14th, 2003 02:11 AM





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