Getting data from a web service

J

John

Hi

What is the way to get data (an sql statement with two tables) via a web
service and store it into a local table? Has anyone actually done this as
most examples I have seen are close but don't exactly do this. Would be
great to have a code example.

Thanks

Regards
 
S

Saurabh Nandu

Yes you can use a DataSet object fill the same object 2 times with different data and pass it along. Once on the client side you receive the DataSet then you can use standard ADO.NET to extract records from the dataset and add it to your local database

I am attaching sample web service code below

twotables.asmx

<%@ WebService language="C#" class="TwoTables" %>

using System;
using System.Web.Services;
using System.Xml.Serialization;
using System.Data.SqlClient ;

public class TwoTables {

[WebMethod]


public System.Data.DataSet GetTwoTables() {
string connectionString = "server=\'(local)\'; trusted_connection=true; database=\'Northwind\'";
System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

string queryString = @"SELECT TOP 10 * from [Orders]";
System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;



System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
dataAdapter.SelectCommand = dbCommand;
System.Data.DataSet dataSet = new System.Data.DataSet();
dataAdapter.Fill(dataSet);

dbCommand.CommandText = @"SELECT TOP 10 * from [Order Details]";
dataAdapter.Fill(dataSet);


return dataSet;
}

}


--
Regards,
Saurabh Nandu
AksTech Solutions, reflecting your needs...
[ www.AksTech.com ]
[ www.MasterCSharp.com ]
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top