Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



Conversion from type 'DBNull' to type 'String' is not valid.,asp.net&vb

Home    ASP .NET    Conversion from type 'DBNull' to type 'String' is not valid.,asp.net&vb

       


Error:Conversion from type 'DBNull' to type 'String' is not valid.

i have a table which contain fields may be null or not null . I tried to fill the data from the table to the dataset 
and assign the each items to the textboxes and dropdownlistes. if field is empty the exception will 
occur.

This is what I understood. U have a table which has no data.
That is DataSet.Tables(0).Rows.Count  = 0 

Before the line where u copy the date to textbox you could write the code like this 

if DataSet.Tables(0).Rows.Count  <>  0 then
txtSomething.text  = DataSet.Tables(0).Rows(0)("COLOUMNNAME")
else
txtSomething.text = ""
endif 

of 

Dim oDataRow as DataRow
For each oDataRow in oDataSet.Tables(0).Rows

txtSomething.text  = oDataRow ("COLOUMNNAME")

EndFor

The first one is useful if it thre are only one row 

if you are populating a listview or something use the second example





  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam