none
Filling a datagrid RRS feed

  • Question

  • I have the following code to fill a datagrid:


            Me.TimeLogEnteredTableAdapter.Fillby _(Me.Msd_database1fDataSetTimeSheet.TimeLogEntered)
      
            Dim TimeLogEntered = From TimeLogEntered2 In Msd_database1fDataSetTimeSheet.TimeLogEntered _
            Where (TimeLogEntered2("Engr") IsNot DBNull.Value AndAlso TimeLogEntered2("Engr") = Me.EngComboBox.Text) _
            Select TimeLogEntered2 

            TimeLogEnteredBindingSource.DataSource = TimeLogEntered.AsDataView

    But I get the following error:

        Operator '=' is not defined for type 'DBNull' and string ""

    for line:

        TimeLogEnteredBindingSource.DataSource = TimeLogEntered.AsDataView


    The fillby has a join so I know that some of the data from one of the tables is null. How can I work around this?
    Thanks
    Thursday, October 16, 2008 12:40 PM

All replies

  • Try including a where clause that will exclude secondary (joined) rows with a null value in a relevant field.

     

    If there is no match for the join, all columns will be null.  If there is a row but the column you care about is null, that is the one to check.

     

    Thursday, October 16, 2008 6:48 PM
  • Thanks very much for the reply.
    What would the where clause look like? This is what mine looks like up to this point:

    Where (TimeLogEntered2("Engr") IsNot DBNull.Value AndAlso TimeLogEntered2("Engr") = Me.EngComboBox.Text)

    Thanks a lot for the help!
    Thursday, October 16, 2008 6:52 PM
  • That looks a bit like basic not SQL.  The SQL code would be like:

     

    SELECT a.ID, b.Address from Names a join Addresses b on a.ID = b.ID Where b.Address is not null

     

    I usually use DBNull.Value as an rvalue not as a test condition but it has been a very long time since I used any flavor of Basic

    Thursday, October 16, 2008 7:06 PM
  • The problem is this grid shows 2 joined tables. One table is a list of all weeks, the other engineers with weeks that they have entered data. So the join is on weeks. I can fill the datagrid with all weeks and engineers data, but when I try to query and refill the grid with the line :
      TimeLogEnteredBindingSource.DataSource = TimeLogEntered.AsDataView

    But I get the following error:

        Operator '=' is not defined for type 'DBNull' and string ""

    The query sees the null cells like in the first 4 rows below and seems to through an error. Is there a way to make it ignore the Nulls?
    Thanks again.



                 Engineer                                      Week
      -122



    934
      -123



    913
      -124



    704
      -125



    935
      -126 Quast 0 8/30/2006 True 649
      -127 Hansen 0 8/3/2007 True 649
      -128 Lemonds 0 11/27/2006 True 649
      -129 Mennecke 0 8/18/2006 True 703

    Thursday, October 16, 2008 7:23 PM
  • Hmmm...

     

    maybe the test:

     

     String.Length == 0

     

    or string.Length = 0 (for VB.Net)

     

    There is an IsNullOrEmpty method in VB.Net Strings that may be useful.

     

     

    Good luck, I may be out of help/ideas.

     

    Thursday, October 16, 2008 7:55 PM
  • The line with the null value for some columns, because thise columns are only in one of the tables, I still want to put into the grid.
    Thursday, October 16, 2008 8:00 PM