PDA

Click to See Complete Forum and Search --> : Webservice question


steve_rm
Dec 29th, 2004, 10:36 AM
Hello,

I am trying to create a webservice that will enable me to retrieve rows from a database in sql. I would like the service to return the datatable filled with the records. So that the consumer can display in a datagrid. But l am not sure if l am going about it correctly.

This is my code below.

[WebMethod (Description="This will get retrieve customers' orders")]
public DataTable RetrieveOrders()
{
SqlConnection cnn = new SqlConnection("Server = Steves-pc; Database = northwind; Integrated Security = yes");
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable("Orders");

string getOrders = "SELECT OrderID,CustomerID,ShipName,ShipCountry FROM Orders";
cmd = cnn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = getOrders;
da.SelectCommand = cmd;

dt.Clear();
da.Fill(dt);

cnn.Close();

return dt;
}
Many thanks in advance,

Steve

Mike Hildner
Dec 29th, 2004, 11:32 AM
Are you having any particular troubles? I do this, but instead I use a DataSet, even for just one table. Now that I think about it, I'm not really sure why, probably because all the examples were like that.