Results 1 to 5 of 5

Thread: sp_executeSQL and dataadapter

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    sp_executeSQL and dataadapter

    hi there

    I was wondering, in C#, is there a way to obtain a datatable or dataset of results when using sp_executeSQL?

    I can use normal SQL queries fine, but when using the stored proc sp_executeSQL, i do not know how to obtain the entire collection of results into a datatable or dataset.

    any ideas?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366

    Re: sp_executeSQL and dataadapter

    PHP Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Diagnostics;

    public class 
    MyClass
    {
        public static 
    void Main()
        {
            
    DataTable authors = new DataTable();
            
    string connString="user id=userid;password=password;server=(local);database=pubs;";
            
    usingSqlConnection cn = new SqlConnectionconnString ) )
            
    usingSqlCommand cmd = new SqlCommand"sp_executesql"cn ) )
            {
                
    cmd.CommandType CommandType.StoredProcedure;
                
    cmd.Parameters.Add"@stmt""select * from authors" );
                
    usingSqlDataAdapter da = new SqlDataAdaptercmd ) )
                {
                    
    da.Fillauthors );
                }
            }
            
    Debug.Assertauthors.Rows.Count 0"authors datatable contains rows" );
        }

    eh eh look familiar?(the place,not me) I'm a BIG fan of the Royal Mile.

  3. #3
    New Member
    Join Date
    Feb 2012
    Posts
    1

    Re: sp_executeSQL and dataadapter

    I had the same situations
    And in my store proc. I had a PRINT command just before sp_executesql

    PRINT @sql

    exec sp_executesql @sql


    And I just remove my PRINT command in my store procedure
    and it's working fine

    Weird ! but it's work for me

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: sp_executeSQL and dataadapter

    this is a thread dated 2004

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: sp_executeSQL and dataadapter

    Quote Originally Posted by HOASTONGE View Post
    I had the same situations
    And in my store proc. I had a PRINT command just before sp_executesql

    PRINT @sql

    exec sp_executesql @sql


    And I just remove my PRINT command in my store procedure
    and it's working fine

    Weird ! but it's work for me
    Not all that weird actually... ANYthing returned back by SQL Server is considered return output. So the PRINT becomes the first resultset, you have to move to the next resultset in order to get past it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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