Cannot get value because it is DBNull.
-
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
-
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
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
-
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
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