Results 1 to 6 of 6

Thread: Stored Procedure, Web Service, Dataset, Argh...

  1. #1

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346

    Stored Procedure, Web Service, Dataset, Argh...

    I have a Web Service that is calling a Stored Procedure in MS SQL 2000, the only problem is i dont remember how to get the returned results from the procedure to show from my web service. I can execute a procedure with no problem as long as i dont get data back, but i am running a procedure to get data back, my return type for the procedure is a DataSet, so i guess i need to get the procedure results into my dataset to return. Help!

    Thanks!
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Something like this:
    Code:
    [WebMethod]
    public DataSet getMyData()
    {
        try
        {
            SqlConnection cn = new SqlConnection("YourConnectionStringHere");
            cn.Open();
    
            SqlCommand cm = new SqlCommand("StoredProcName", cn);
            SqlDataAdapter da;
            DataSet ds = new DataSet();
    
            cm.CommandType = CommandType.StoredProcedure;
    
            //if you have parameters, add them here
            //cm.Parameters.Add("@ParameterName", SqlDbType.Int);
            //cm.Parameters["@ParameterName"].Value = YourValueHere;
    
            da = new SqlDataAdapter(cm);
            da.Fill(ds, "MyData");
    
            cn.Close();
            return ds;
        }
        catch(Exception ex)
        {
            //here do something with the execption
        }
    }

  3. #3

    Thread Starter
    Hyperactive Member kleptos's Avatar
    Join Date
    Aug 2001
    Location
    The Dark Carnival
    Posts
    346
    That worked! Thanks!
    ..::[kleptos]::..
    • Database Administrator (MSSQL 2000)
    • Application Developer (C#)
    • Web Developer (ASP.NET)


  4. #4
    Member
    Join Date
    Jun 2006
    Location
    Heaven
    Posts
    39

    Re: Stored Procedure, Web Service, Dataset, Argh...

    Dear Serge or any one else can explain these steps.... infact i will be realy thankful

  5. #5
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: Stored Procedure, Web Service, Dataset, Argh...

    He created a method, getMyData, that can be called as a webservice method to return a dataset object. The method simply creates a connection to the database, creates a dataset object, fills that object with data, and returns it. Does that make sense?
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  6. #6
    Member
    Join Date
    Jun 2006
    Location
    Heaven
    Posts
    39

    Re: Stored Procedure, Web Service, Dataset, Argh...

    thanks DNA

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