468,117 Members | 1,580 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,117 developers. It's quick & easy.

Problem Returning a DataTable Object from C# Web Service

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

Sep 21 '06 #1
5 4762
Hi,

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

"Jim Murphy" <Ji*******@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...
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

Sep 21 '06 #2
Yes, there is a directive in the C# client and the C# service of:

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

Thanks

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

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

"Jim Murphy" <Ji*******@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...
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


Sep 21 '06 #3
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.myselect2Resp onseMyselect2Result' to
'System.Data.DataTable'
C:\Program Files\Microsoft Visual Studio
8\VC#\Programs\TestWebServiceClient\TestWebService Client\Form1.cs
36 30 TestWebServiceClient

Thanks

"Jim Murphy" wrote:
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
Sep 21 '06 #4
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 !

Sep 22 '06 #5
Yes, I tried a cast, but get this message when I try to build the client ->

Cannot convert type
'TestWebServiceClient.TestWebService.myselect2Resp onseMyselect2Result' to
'System.Data.DataTable'

"coolCoder" wrote:
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 !

Sep 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Golawala, Moiz M (GE Infrastructure) | last post: by
1 post views Thread by Karuppasamy | last post: by
reply views Thread by Junjie Wang | last post: by
6 posts views Thread by Scott Zabolotzky | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.