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
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