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.