Problem Returning a DataTable Object from C# Web Service

G

Guest

In creating a C# web service, I am having trouble returning a DataTable
object as the result of a web method. I have no problem returning native
types like string or int, but cannot return a .NET DataTable object. The
problem occurs when I try to compile the client side C# application (it
complains about the DataTable type not being recognized as the return of the
web service method).
Thanks
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

A dumb question, did you include a "using System.Data;" directive?
 
G

Guest

Yes, there is a directive in the C# client and the C# service of:

using System.Data;
using System.Data.Odbc;

Thanks
 
G

Guest

As additional info, the method signature for the web service method is:


Using System.Data;
Using System.Data.Odbc;

[WebMethod]
public DataTable myselect2 (string aconnectionstrng, string asql)


On the client side, I have:


using System.Data;
using System.Data.Odbc;

DataTable aresultset;
string aconnectionstrng,asql;

aconnectionstrng = "A CONNECTION STRING";
asql = "A SQL STATEMENT";

Service aservice = new Service();
aresultset = aservice.myselect2(aconnectionstrng, asql);



I get an error when I try to build:

Error 2 Cannot implicitly convert type
'TestWebServiceClient.TestWebService.myselect2ResponseMyselect2Result' to
'System.Data.DataTable'
C:\Program Files\Microsoft Visual Studio
8\VC#\Programs\TestWebServiceClient\TestWebServiceClient\Form1.cs
36 30 TestWebServiceClient

Thanks
 
C

coolCoder

Hi,
Just to check, whether you tried explicitly converting the out put
to data table type ?

like -

aresultset = (DataTable) aservice.myselect2(aconnectionstring,
asql);


If not please try it.
using System.Data;
using System.Data.Odbc;

DataTable aresultset;
string aconnectionstrng,asql;

aconnectionstrng = "A CONNECTION STRING";
asql = "A SQL STATEMENT";

Service aservice = new Service();
aresultset = aservice.myselect2(aconnectionstrng, asql);



Thanks !
 
G

Guest

Yes, I tried a cast, but get this message when I try to build the client ->

Cannot convert type
'TestWebServiceClient.TestWebService.myselect2ResponseMyselect2Result' to
'System.Data.DataTable'
 

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