I am trying to test different queries on a dataset from an existing Sql Server DB. I need to be able to grab a row by its id column for the project I am doing. What seems like a straightforward query gets no results however.
DataSet prodspdata = new prodspDataSet();
DataRow[] load;
load = prodspdata.Tables["TripNumber"].Select("[ctripnumber] = '21605178'");
Console.WriteLine(load.Length);
Console.ReadLine();
Output from load.Length
is 0. I understand from documentation that load should be an array of rows returned from the Select()
query. I know that this result exists from looking in the data so I expect load.length
to be 1.
I tested a query from within Sql Server Management Studio to make sure I wasn't missing something:
SELECT * FROM TripNumber WHERE ctripnumber = '21605178'
This returns the 1 row as expected.
Is my Select query bad? I am brand new to C#, am I testing it wrong? I simply need to know if load
contains any results so I know that my query works as intended.
EDIT: So it appears my DataTable has no rows.
DataTable loadTable;
loadTable = prodspdata.Tables["TripNumber"];
Console.WriteLine(loadTable.Rows.Count);
Console.ReadLine();
This returns 0
rows whereas loadTable.Columns.Count
gives me 133
Did I miss a step, perhaps something to do with a TableAdapter?