Results 1 to 2 of 2

Thread: Webservice question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

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

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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
  •  



Click Here to Expand Forum to Full Width