Results 1 to 14 of 14

Thread: Displaying Null values from database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Displaying Null values from database

    Hi
    I have a grid and when i select a row from it if it has null values it should also be displayed. How can i do this???

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    What type of grid? There ae several in the .NET Framework, not to mention numerous third-party grids too. Please make your questions as specific as possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Displaying Null values from database

    its a data grid...i use it to show details from the database......i get an error whn few of the fields in the database r empty.....but i want to display those empty fields also......

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    So it's a System.Windows.Forms.DataGrid, definitely not a DataGridView?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Displaying Null values from database

    I have a little question here. What is the difference between DataGrid and DataGridView? On MSDN gives a quite smiler explanation.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    Quote Originally Posted by eranga262154
    I have a little question here. What is the difference between DataGrid and DataGridView? On MSDN gives a quite smiler explanation.
    The DataGridView was written from the ground up and added to the Framework in version 2.0 as a replacement for the DataGrid. It is much more functional and easier to extend.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Displaying Null values from database

    You mean a whole database?
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Displaying Null values from database

    Its a data grid view......so wht do i do to display th null values also??? mostly i will b retriving only one value at a time..but thr may b cases whr i need to get different values also.......To be more specific i'll be displaying only one row from the database....but thr may be cases whr i need to show multiple rows.....so wht do i do??
    Last edited by arunhere; Jul 24th, 2007 at 09:42 PM. Reason: To be more specific

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    It's very importatnt that you use the proper names for things. The DataGridView behaves quite differently to the DataGrid, which is why I was so careful to qualify. Advice given for one is likley to be useless for the other.

    You need to set the DefaultCellStyle.NullValue property of the column. For instance, if you wanted to display "{null}" in cells with null values in the second column you would do this:
    vb.net Code:
    1. Me.DataGridView1.Columns(1).DefaultCellStyle.NullValue = "{null}"
    If you're creating your columns in the designer then you should also set the NullValue in the designer rather than in code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Displaying Null values from database

    Look that pretty easy to me. But what happened if there is large number of columns.
    Last edited by eranga262154; Jul 25th, 2007 at 01:05 AM. Reason: Incomplete
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    Quote Originally Posted by eranga262154
    Look that pretty easy to me. But what happened if there is large number of columns.
    We're talking columns, not rows. You set that property for the column and then every cell in that column will display that value for nulls, even if there are millions of rows.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Thumbs up Re: Displaying Null values from database

    Thank guys......But i needed th code to b in c#......and abt the names i'll be more carefull from now on......

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Displaying Null values from database

    Code:
    this.DataGridView1.Columns[1].DefaultCellStyle.NullValue = "{null}";
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Displaying Null values from database

    Thank you very much buddy......

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