Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to load a DataSet, but it is always null. Regular sqlReader.GetValue() is not
    primarykey
    data
    text
    <p>I don't use DataSets much. Usually find myself using an ORM or just a basic sqlReader.Read() followed by some GetValues(). I'm working on some legacy code that has DataSets all over the place, and while fixing a bug was trying to DRY some of it up.</p> <p>However, I can't seem to actually get the data loaded into a non-typed DataSet. </p> <pre><code>public static DataSet ExecuteStoredProcedure(string storedProcedure, DBEnum db, IEnumerable&lt;SqlParameter&gt; parameters) { DataSet result = new DataSet(); using (SqlConnection connection = SqlHelper.GetSqlConnection(db)) { SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = storedProcedure; if (parameters != null) foreach (SqlParameter parameter in parameters) command.Parameters.Add(parameter); connection.Open(); DataTable table = new DataTable(); using (SqlDataReader reader = command.ExecuteReader()) { table.Load(reader); } result = table.DataSet; // table.DataSet is always empty! } return result; } </code></pre> <p>I assumed table.Load(reader) does all the necessary reader.Read() calls ... but I went ahead and tried it both with and without reader.Read() before the table.Load(), to no avail.</p> <p>I know that the stored procedure being called is actually returning data. If I do something like this, I see the data just fine:</p> <pre><code>using(SqlDataReader reader = command.ExecuteReader()) { reader.Read(); object test = reader.GetValue(0); // returns the expected value } </code></pre> <p>Seems like I'm missing something simple here, but I've been scratching my head over this one for a while now.</p> <p>This is in .NET 3.5.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload