Need Help with DataSets BAD!!!

G

Guest

I have an error happening when I run the folowing code. It's one of the
Continue / Break ones that states that there is an unhandled exception and
it's System Error. No more info from Visual Studio.

Here is the code. The first section is my code in a class (DLL) that I have
referenced. I have an object instantiated called objSQL. This object
handles all SQL functions. The database connection is persistant. The
second section is where I get my error. In my main form I have tried to NOT
use Imports System.Data and .SQLClient. I have also tried this completely
within the form using the Imports. I get the same error.

Here is the code:
Code: Method within the SQL Class for Data Adapter -
objSQL.getDataAdapter(String)
Note: dbconn is the connection within the class. Connection is persistant

Public Function getDataAdapter(ByVal strSQL As String) As SqlDataAdapter
Try
getDataAdapter = New SqlDataAdapter(strSQL, dbConn)
Catch ex As Exception
RaiseEvent ErrRaised(ex.Source, ex.Message)
End Try
End Function

Code: Event in View Button

Dim strCustID as string = txtCust.text
Dim strSQLCust as string = "SELECT * AS Cust FROM tblCustomers WHERE
CustID = " & strCustID
Dim ds As New DataSet
Dim daCust As SqlClient.SqlDataAdapter
daCust = objSQL.getDataAdapter(strSQLCust)
daCust.Fill(ds, "Cust") *********************** ERROR HERE

I've done this before and had it working. But that was ASP.NET (VB). I'm
wondering if there is a difference that I'm not seeing.

Note: This is only a portion of the code in the event. My goal is to have a
DataSet with multiple columns to use as a basis for an XML Schema and then
use the schema as a dataset in a Crystal Report.

Thank you for all your help

Ron.
 
C

Cor Ligthert

Ron,

First something in general. It is strongly advices not to make persisitent
connections in dotNet 2002/2003 using SQLClient.

The import does nothing it is only to help you not to type the prefixes
everytime.

Your dataset is persistent. While it is in ASPNET when you have not set it
in a Session every time new.
(This can be the reason of the error because that you probably can get now
concurrency errors, clean it and the tables when that does not help before
the fill).

What is the easy to do in a windowforms application, while you have in a
Webform application to make a redirect, is this when you are testing. That
try block should be in my opinion there for ever in a better way.

Try
daCust.Fill(ds, "Cust") *********************** ERROR HERE
Catch ex as exceptiong
messagebox.show(ex.tostring)
End Try

I hope this helps,

Cor
 
G

Guest

Cor,
Thank you again for helping me find an answer. I really appreciate your time.

Here's what I found.

The message indicated that the Adapter did not like the AS Cust in the SQL
statement. It works when I use it in SQL Query Analyzer. I think it has to
do with the wildcard *. I'll try it by listing out the columns. The AS
works in all my other SQL statements though.

I removed the AS Cust and everything works.

I now have a XSD schema that shows all the info I'm looking for.

Thanks again.

Ron.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top