Convert regular DataSet to strongly typed DataSet

M

moondaddy

Is there a way to convert a regular dataset to a strongly typed dataset?
I'm receiving a dataset from a webservice and when it was created on the
server, it was created as a strongly typed dataset. However, the return
type of the webservice is just Dataset because they can not return strongly
typed datasets (as far as I know...). Now back on the client, I want to use
this dataset as a strongly typed one. I get a cast exception if I do
something like this

dim ds as dsCustomer = CType(MyWebServiceCall(CustID),dsCustomer).

Even though this line doesn't work, it shows you what I want to do. Any
good ideas?
 
K

Kevin Yu [MSFT]

Hi moondaddy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to cast an untyped DataSet
returned from web service to a typed one. If there is any misunderstanding,
please feel free to let me know.

We cannot cast an untyped DataSet to a typed one directly. However, as far
as I know, we can return a typed DataSet from a web method. If you are
referencing a web service in your project, the proxy will create the
definition of the typed DataSet automatically for you. So you can create
strong typed DataSet object directly from the client machine.

If you are returning a typed DataSet named MyDataSet, you can achieve this
with the following code.

Dim ds As localhost.MyDataSet
Dim s As New localhost.Service1
ds = s.GetMyDataSet()

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
M

moondaddy

It doenst compile for me.

wsMain is the web reference in the winforms project
dsUser is the typed dataset in both the client app and in the server
webservice

Dim dataService As wsMain.wsMain = GetWebServiceReference(username,
password)

Dim ds As dsUser
ds = dataService.Authenticate()
I get a squigly undeer "dataService.Authenticate()"
Here the squibly say:
Value of type 'CharmpixAdmin_01.wsMain.dsUser' cannot be converted to
'CharmpixAdmin_01.dsUser'.

and if I try

Dim ds As dataService.Authenticate()

I also get a squigly undeer "dataService.Authenticate()"
Here the squigly says "Typed 'dataService.Authenticate' is not defined."
 
K

Kevin Yu [MSFT]

Hi moondaddy,

This doesn't complie because "Dim ds As dsUser" is incorrect. Because
dsUser refers to the typed DataSet on the client side. Although dsUser and
wsMain.dsUser may have the same name and maybe same schema, the compiler
regards them as different objects, and they cannot be casted between each
other. So please try to use the following instead.

Dim ds As wsMain.dsUser

I assume that the dsUser is also defined in the web serivce, so that VS.NET
IDE will create the same class in proxy.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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