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.
Many thanks in advance,VB Code:
[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; }
Steve




Reply With Quote