473,402 Members | 2,046 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,402 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 4948
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.