Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null Data In DataGridView

Status
Not open for further replies.

SorryDog777

Programmer
Jun 26, 2003
15
US
There is probably a simple answer for this question, but I have just run out of steam looking for the solution!

I have a unbound DataGridView on a form that a user populates. Some cells in the grid can contain null values.

I'm attempting to read the values from the cells to put into a custom database table with the below example:



Dim strCellString as String

strCellString = DataGridView1.Rows(1).Cells(1).Value.ToString


If the current is null the get the exception error. I also tried this statement

strCellString = IIf(DataGridView1.Rows(1).Cells(0).Value.ToString, DataGridView1.Rows(1).Cells(0).Value.ToString, "")

Also gives an exception.

Any suggestions to test for null without using the On Error, Resume Next statement?

Thanks.

 
Use the IsDBNull function:

if not IsDbNull(DataGridView1.Rows(1).Cells(1).Value) Then
strCellString = DataGridView1.Rows(1).Cells(1).Value.ToString
End If

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top