473,221 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

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 4943
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
1
by: Karuppasamy | last post by:
H I have a WebService calling a Method in a Remote Object. The Remote method Returns an Object. This Webservice also returns the same object. All things are working fine when this Web Service is...
2
by: alan | last post by:
Hi Does primarykey property on the datatable object always need to be set in your code (for use with datarow.find) or should this be set automatically from your database tables primary key coz this...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
0
by: Junjie Wang | last post by:
I define a DataTable object in the aspx: Dim m_theDataTable As New DataTable() which is a member variable of the page class. I use the following code to bind it to the grid: Dim...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
5
by: Chris Lee | last post by:
I have a vexing problem with an object of multidimensional array. The function I call (an external com function) is supposed to return a 2-D array that looks like this: (0,0), (1,0) ......, (n,0)....
5
by: morz | last post by:
classA { public: thirdPartyThreadLibrary myThread; void Run() { myThread.exec(); // created new thread and run on background. }
2
by: DSilent | last post by:
Hi guys, i have a problem with my windows service project. I already publish that to my localhost and install it. The installation file has been created. But at the same time, a message box appear...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.