Results 1 to 13 of 13

Thread: Remove empty records?[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Talking Remove empty records?[Resolved]

    How can I omit these spaces(empty strings) while looping through all data in specific column (when I load them , they are there in the dataset) have a look at the attachted image to have better idea of what I'm talking about , if not clear plz let me know !

    Thanks
    Attached Images Attached Images  
    Last edited by Pirate; May 6th, 2003 at 12:12 PM.

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    are they empty strings or null values?

    if they are empty strings do a strComp(string1, "") = 0 then don't do anything, or if it's null do if DBnull(string1) then don't do anything.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Yeah they are null values , I do know how to use DBNull.Value . How would you apply it here ?

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    not sure if i completely understand what you are doing but wouldn't it be better to just have 2 columns.
    1 is the overall name, and the second the title e.g.

    java : widgets
    java : buttons
    xml : stylesheets
    vb : forms
    java : stuff

    then you can query the table putting java, xml, or vb in the where part.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I wanted it that way if possible . I'm sure it's but I can't go around it thought !

  6. #6
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    i mean that's how you need to design the database table. I pressume that's where you are getting the data from.

    column1 : MainGouping
    column2 : Title

    design the table like that.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    If I changed that then I would have to change lots of lines and rebuilding similar structure as you suggested doesn't neccessarily fits my situation thanks though !

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its the DB structure that creates the blank lines as nswan said. You can only delete a row at a time which then would remove the items that aren't blank in the same row as well. So there is no way without changing the structure as nswan suggested.

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    you could pull out an entire row though and then check for null values on each item in the datarow. Just trying to figure out how to check for nulls at the mo!
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    But how would you put the data back in for the rows that have half null and half not? To check for Null you can just use [fieldname] Is Null

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    nswan , that would take more time and won't help I guess .

    I can remove them from combobox (I did actually but I don't want even to include them in the dataset )
    This is how I populate a combobox with all records in a column , How can I use Is Null operator in this case Edneeis ?
    VB Code:
    1. Public Shared Sub ShowRecords(ByVal ComBox As ComboBox, ByVal TableStr As String, ByVal ColumnStr As String)
    2.         OpenDB()
    3.  
    4.         Dim adoTables As New OleDb.OleDbCommand("Select * From " & TableStr & "", MyConnection)
    5.         Dim adoReader As OleDb.OleDbDataReader
    6.         Dim strTable As String
    7.  
    8.         ComBox.Items.Clear()
    9.         Try
    10.             adoReader = adoTables.ExecuteReader()
    11.             While (adoReader.Read)
    12.                 strTable = adoReader.Item(ColumnStr).ToString
    13.                 ComBox.Items.Add(strTable)
    14.             End While
    15.         Catch myException As Exception
    16.             MessageBox.Show(myException.ToString())
    17.         Finally
    18.             adoReader.Close()
    19.             adoReader = Nothing
    20.             adoTables = Nothing
    21.         End Try
    22.     End Sub

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    So you are making a seperate trip to the db for each combo?

    If thats the case then you can weed out the Nulls in the query:
    VB Code:
    1. Dim adoTables As New OleDb.OleDbCommand("Select " & ColumnStr & " From " & TableStr & " WHERE Not " & ColumnStr & " Is Null", MyConnection)

    This will also reduce traffic since you only need the one column there is no need to return all of them. Hence the Select specifies the column name instead of * for all of them.

  13. #13

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I was sure you will beat it , that's exactly what I need .
    It Worked like a charm ! Thank you Edneeis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width