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.

VB Code:
  1. [WebMethod (Description="This will get retrieve customers' orders")]
  2.         public DataTable RetrieveOrders()
  3.         {
  4.             SqlConnection cnn = new SqlConnection("Server = Steves-pc; Database = northwind; Integrated Security = yes");
  5.             cnn.Open();
  6.             SqlDataAdapter da = new SqlDataAdapter();
  7.             SqlCommand cmd = new SqlCommand();
  8.             DataTable dt = new DataTable("Orders");
  9.        
  10.             string getOrders = "SELECT OrderID,CustomerID,ShipName,ShipCountry FROM Orders";
  11.             cmd = cnn.CreateCommand();
  12.             cmd.CommandType = CommandType.Text;
  13.             cmd.CommandText = getOrders;
  14.             da.SelectCommand = cmd;
  15.  
  16.             dt.Clear();
  17.             da.Fill(dt);
  18.  
  19.             cnn.Close();
  20.  
  21.             return dt;             
  22.         }
Many thanks in advance,

Steve