I'm really puzzled about this. I have a table in SQL Server with three nvarchar(255)
columns and a couple rows just for testing. the following code correctly returns the column names and the row count of 2 but Rows.List = null
. If I use reader.Read()
I can read the data in the rows so the query is returning the data. Any query that alters the data in the tables such as an INSERT INTO ...
will work perfectly.
DataTable results = new DataTable;
int rowsAffected = 0;
string connectionString = "Server=<serverName>;Database=<databaseName>;Integrated Security=SSPI";
string query = "SELECT * FROM testTable";
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand command = new SqlCommand(query, conn))
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
rowsAffected = dataAdapter.Fill(results);
When this is done, results.Rows.Count = 2
which is correct, and results.Rows.List = null
which is WRONG. Why isn't there any data being returned to me?