Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cannot get value because it is DBNull.

Cannot get value because it is DBNull.

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Dear Friends, I have small webapplication. I have one webform.aspx page on which I display the customerdetail from cusdetail table. but since some of my fields are empty when I execute the page it gives me the error "Cannot get value because it is DBNull." and when I clicked Next or previous button it gives me error like "Cast from type 'DBNull' to type 'String' is not valid." the code is as below. Private Sub TxtCusCode_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtCusCode.DataBinding Dim RecordPos As Integer = CType(Session("RecordPos"), Integer) TxtCusCode.Text = Ds.CusDetail(RecordPos).CusCode TxtCusName.Text = Ds.CusDetail(RecordPos).CusName TxtCusTelNo.Text = Ds.CusDetail(RecordPos).CusTelno TxtCusID.Text = Ds.CusDetail(RecordPos).CusIDNo TxtCusJob.Text = Ds.CusDetail(RecordPos).CusJob CmbBooking.DataTextField = Ds.CusDetail(RecordPos).WayOfBooking End Sub when I make comments for cusidno which is empty then its works fine. even How can i assigne the value to the dropdownlist text field I want to show the value on 0th index of dropdownlist. to display the value of current record. Your quick response will be highly appreceiated Thanks Murtuza -- modified at 4:19 Tuesday 6th September, 2005

    R 1 Reply Last reply
    0
    • L Lost User

      Dear Friends, I have small webapplication. I have one webform.aspx page on which I display the customerdetail from cusdetail table. but since some of my fields are empty when I execute the page it gives me the error "Cannot get value because it is DBNull." and when I clicked Next or previous button it gives me error like "Cast from type 'DBNull' to type 'String' is not valid." the code is as below. Private Sub TxtCusCode_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtCusCode.DataBinding Dim RecordPos As Integer = CType(Session("RecordPos"), Integer) TxtCusCode.Text = Ds.CusDetail(RecordPos).CusCode TxtCusName.Text = Ds.CusDetail(RecordPos).CusName TxtCusTelNo.Text = Ds.CusDetail(RecordPos).CusTelno TxtCusID.Text = Ds.CusDetail(RecordPos).CusIDNo TxtCusJob.Text = Ds.CusDetail(RecordPos).CusJob CmbBooking.DataTextField = Ds.CusDetail(RecordPos).WayOfBooking End Sub when I make comments for cusidno which is empty then its works fine. even How can i assigne the value to the dropdownlist text field I want to show the value on 0th index of dropdownlist. to display the value of current record. Your quick response will be highly appreceiated Thanks Murtuza -- modified at 4:19 Tuesday 6th September, 2005

      R Offline
      R Offline
      Rahul Walavalkar
      wrote on last edited by
      #2

      Compare the fetched record with DBNull.Value and store either the value or a blank string in the textboxes. Something like TxtCusName.Text = Ds.CusDetail(RecordPos).CusName==DBNull.Value?"":Convert.ToString(Ds.CusDetail(RecordPos).CusName); This is C# code.. pls change it to your respective language.. It will check if the value returned by the CusName is and if yes, will store a blank string in the textbox. regards, [r a w] I do not understand what I do. For what I want to do I do not do, but what I hate I do. - Romans 7:15

      L 1 Reply Last reply
      0
      • R Rahul Walavalkar

        Compare the fetched record with DBNull.Value and store either the value or a blank string in the textboxes. Something like TxtCusName.Text = Ds.CusDetail(RecordPos).CusName==DBNull.Value?"":Convert.ToString(Ds.CusDetail(RecordPos).CusName); This is C# code.. pls change it to your respective language.. It will check if the value returned by the CusName is and if yes, will store a blank string in the textbox. regards, [r a w] I do not understand what I do. For what I want to do I do not do, but what I hate I do. - Romans 7:15

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Dear Rahul, Thank you very much for your quick response. Could u please give me this syntax in VB.Net. Cause when I tried according to me it gives me other error like there is no row at position 0. TxtCusName.Text = Ds.CusDetail(RecordPos).CusName==DBNull.Value?"":Convert.ToString(Ds.CusDetail(RecordPos).CusName); I think I am not converting properly the code u gave me in C# to VB.NET code Thanks Murtuza

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups