By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

Problem Returning a DataTable Object from C# Web Service

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.