How to Stop OleDbDataReader Getting NULL(s)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to Stop OleDbDataReader Getting NULL(s)

  1. #1
    Join Date
    Jun 2010
    Posts
    15

    Post How to Stop OleDbDataReader Getting NULL(s)

    Hi guys ,
    I am doing a very simple connection with C# and Ms Access and so far every thing goes fine, with me!.I just have a problem on retrieving Null values.the code that I am using to list values of a field in a table is like:

    OleDbCommand cmd = new OleDbCommand(sql, cn);
    reader = cmd.ExecuteReader();
    while (reader.Read()){
    listAtt.Items.Add(reader.GetValue(0).ToString());
    }

    as I told you this code works fine and get values of the field but it it return NULL values as well and when I want to list the values in a ListBox they appears like a space in the listbox display as they are a type of data.
    Now my question is that how I can stop getting Nulls or not displaying them on the ListBox?!
    I appriciate if you give me a good hint on that and also provide me some hints or #Ref to teach me how I can display the query results on a Grid format like a real table(Tabular) in a RichTextbox(or TextBox)?

    Thanks again
    Behrouz

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: How to Stop OleDbDataReader Getting NULL(s)

    You can either modify the SQL to not return nulls, or put a condition into your code, I don't see other option.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    May 2002
    Posts
    484

    Re: How to Stop OleDbDataReader Getting NULL(s)

    string myField = reader.IsDBNull(0) ? String.Empty : reader.GetString(0);

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: How to Stop OleDbDataReader Getting NULL(s)

    OK. I've miss the point to keep the space.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center