troubleshooting Question

No value at index 1 when testing to see if value in datagrid

Avatar of running32
running32 asked on
Visual Basic.NET
5 Comments1 Solution168 ViewsLast Modified:
I need to see if there is a value in datagrid.  My problem is that I keep getting the error No value at index 1 when I try and test DataGrid1(i, 0).ToString = "".  When I am testing there is a value in 0 but not in 1. How can I see if there is something in row 1.  Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
 Dim i = DataGrid1.VisibleRowCount
            i = i - 1
 
Do While i <> -1
 
                    If DataGrid1(i, 0).ToString = "" Then
                        Try
 
 
                            If IsDBNull(DataGrid1.Item(i, 0)) = True Then
                                Exit Sub
                            End If
 
                            If IsDBNull(DataGrid1.Item(i, 0)) = False Then
                                receipt = DataGrid1.Item(i, 0)  'Column 3
                            End If
 
                            If IsDBNull(DataGrid1.Item(i, 1)) = False Then
                                qty = DataGrid1.Item(i, 1)  'Column 2
 
                                'get the mfgprice of the product.
 
                                retailprice = qty * mfgprice
 
                            End If
                            If IsDBNull(DataGrid1.Item(i, 2)) = False Then
 
                                comment = DataGrid1.Item(i, 2)  'Column 3
                            End If
 
                            '  If IsDBNull(DataGrid1.Item(i, 4)) = False Then
                            '  uid = DataGrid1.Item(i, 4)  'Column 3
                            '  End If
 
                            create = SqlParametersDB.Name.UserName
                            ' If uid = "" Then
                            Dim cmdunarchive1 As New SqlClient.SqlCommand("insert into tblPAMfgReceipt (lngappid,dtmreceipt, sglqty, strcomment, strcreate, dtmcreate) values ('" & appid & "','" & receipt & "','" & qty & "','" & comment.Replace("'", "''") & "','" & create & "','" & Now & "')", Connection1)
                            Try
                                cmdunarchive1.ExecuteNonQuery()
                            Catch ex As Exception
                                MsgBox(ex.Message)
                            End Try
                            '   End If
 
 
 
                        Catch ex As Exception
                            MsgBox(ex.Message)
                        End Try
                    End If
 
                    i = i - 1
                Loop
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros