Can't get my null values!

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
My TableAdapter links to a table with null values in some of the cells.

Whenever I preview the data in the TableAdapter, null value fields are displayed.

Whenever I try to populate or do a query using the values, rows with null values never even seem to show up!

Has anyone ever encountered something like this? Any idea how to get around it?
 
Not sure what you mean by this. Can you show an example?
I have a TableAdapter linked to an SQL Server 2000 table. Some of the cells have null string values.

In VS2005, I can preview the data linked by the TableAdapter in design mode, and all fields are displayed - even the ones with cells containing null values (they just show "null" in the cell).

When I run my application, I create a DataTable and use an SqlDataAdapter to fill the DataTable using the TableAdapter.

To search my data, I use the DataTables Select method; however, any row that contains a null value does not show up in the returned DataRows.

Since the TableAdapter sits in the IDEs design mode, so I dont know *how* to show the code.

However, I found a solution here: http://tinyurl.com/28u3xg

Basically, I edited the SELECT statement that my TableAdapter used. If the row IS NULL, I replace the value with a single space.

If anyone knows of any issues Im likely to run into because of this, please let me know.
 
Replacing a null with a space is a hack IMO.

What is the search criteria that youre using that isnt returning the expected results? Are you saying youre searching on a column that has a value in the search criteria and its not being returned because another column in that row is null?
 
My TableAdapter is set to return all values:
Code:
SELECT [NAME],[NUM],[DATE],...,[etc.]
FROM dbo.EmployeeTable
Thats all. Nothing special. All values are strings, which was not my design, but company cant stop production to change all the applications that use it right now.

I can go to the TableAdapter in the .xsd file, right click on the "Fill, GetData()" method, select "Preview Data," and the rows where the DATE values are NULL show up right beside everything else on the screen. When the form loads, it Fills the DataGridView, and all of the data shows up - even rows where DATE=NULL.

Now comes the Gotcha:

I have DataTables defined that map to each of the tables in the DataSet:
Code:
DataTable m_empDT = this.DataSet1.EmployeeTable;
To search data in my tables, I fill an array of DataRow values:
Code:
DataRow[] Rows = m_empDT.Select("NAME=SMITH");
There are multiple rows where NAME=SMITH, and some of them contains a DATE=NULL. But, whenever I step through the rows that were returned, the SMITH with DATE=NULL does not show up:
Code:
foreach (DataRow row in Rows)
{
  Console.WriteLine(row.ToString());
}
What? Youre crazy!
Right?

So, yeah, I had to use a hack, but until someone can lead me on how to display this data... Hack, hack, hack!
 
Is it possible that the null date rows have an extra space or something at the end of the Smith? I cant see how the null value in a field would affect the query.
 
Back
Top