Solved

Conversion problem

Posted on 2006-06-21
3
186 Views
Last Modified: 2010-08-05
Public Sub GetPathway(ByVal vABR_ID$)
        If SqlConnection1.State = ConnectionState.Closed Then
            SqlConnection1.Open()
        End If
        Dim DsPathway1 As String
        SqlDiplomateAdapter.SelectCommand.Parameters("@abr_id").Value = vABR_ID
        SqlDiplomateAdapter.Fill(DsPathway1)

The above code is an attempt to populate th a dataset.

However, the dataset includes to fields one is nvarchar and the other is a bit.  I'm getting an error say that  "As Interger  Value of type "string cannot be converted to System.Data.DataSet"
and
"As Interger  Value of type "string cannot be converted to System.Data.Datatable"

can I assume that that's because of the BIT?  What options do I have?

Regards
0
Comment
Question by:TimSweet220
3 Comments
 
LVL 12

Expert Comment

by:fruhj
ID: 16955803
Dim DsPathway1 as string...

Did you mean to dim this as a dataset?
0
 

Author Comment

by:TimSweet220
ID: 16955837
DsPathway1 is a dataset already created from a DataAdapter
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 16956052
The first error probably relates, with its reference to DataSet, to this line

        Dim DsPathway1 As String

As you say, "DsPathway1 is a dataset ...".  You therefore cannot Dim it here As String (or if you do, you will have problems).

The second error probably relates, with its reference to DataTable, to this line

        SqlDiplomateAdapter.Fill(DsPathway1)

DataAdapters fill DataTables, not DataSets.  True, you can call .Fill(dataset) but that will just create a new table within the dataset that it can fill.  I anticipate - from what you say about the dataset being "... already created from a DataAdapter" - that you selected the "Generate Dataset ..." option when you were configuring the dataadapter and, if that is the case, there will be a specific datatable within the dataset that you probably need to specify in the call to the .Fill method.  So I think that line should probably be something like

        SqlDiplomateAdapter.Fill(DsPathway1, "MyTableName")

A couple of other points.  One is that, with dataadapters, you don't need explicitly to open their connections: they handle that automatically.  So these lines

        If SqlConnection1.State = ConnectionState.Closed Then
            SqlConnection1.Open()
        End If

are unnecessary.

And (although perhaps it doesn't matter in practice, I'm not sure) the argument that you pass to your sub is vABR_ID$, but the Value that you give to your parameter is vABR_ID.

What I think your sub ought to look like is this

Public Sub GetPathway(ByVal vABR_ID$)
        SqlDiplomateAdapter.SelectCommand.Parameters("@abr_id").Value = vABR_ID$
        SqlDiplomateAdapter.Fill(DsPathway1, "MyTableName") '<<< you put the right value in here

The Bit field shouldn't cause a problem but, even if it does, I don't thnk you've reached that problem yet ;-)

Roger
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question