|
-
Dec 29th, 2004, 11:36 AM
#1
Thread Starter
Frenzied Member
Webservice question
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:
[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
-
Dec 29th, 2004, 12:32 PM
#2
Frenzied Member
Re: Webservice question
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|