New to VB.NET

jimmyray

Member
Joined
Dec 30, 2009
Messages
14
Programming Experience
Beginner
I have a program that uses crystal reports and sql database. When I right click and try to click report in my program on my formreportviewer I get this error.

Conversion to "" to type integer is not valid.

I have been looking for days. How can I find where this error is happening??
 
Don't you mean: "Conversion from "" to type integer is not valid."

In that case, use the TryParse() method, which takes 2 arguments: the first is the string to convert from; the second is the number to convert into. Example:

Dim mystring As String, mynum As Integer
Integer.TryParse(mystring, mynum)

If the string is empty or non-numeric, this method will return a 0 without generating an error.
 
This is the code I think is giving me an error.

Dim FrmReportViewer As New FormReportViewer
If IsNumeric(dgSearch.Item(dgSearch.CurrentRowIndex, 1)) Then
FrmReportViewer.intPatientID = CInt(dgSearch.Item(dgSearch.CurrentRowIndex, 1))
FrmReportViewer.ShowDialog()
Else
MsgBox("PatientID is invalid")
End If

I understand the error because it looks like PatientId is filled with "test" Which is the LastName field from my table. Not sure why it is trying to use last name.....
 
Hi

In
VB.NET:
If IsNumeric(dgSearch.Item(dgSearch.CurrentRowIndex, 1)) Then
FrmReportViewer.intPatientID = CInt(dgSearch.Item(dgSearch.CurrentRowIndex, 1))
what are the indexe "1" for? Perhaps you have an look on it.
 
Which is the LastName field from my table. Not sure why it is trying to use last name.....

Because this ...

dgSearch.Item(dgSearch.CurrentRowIndex, 1)

is telling IsNumeric to get the value from the second column in your datagrid. The PatientID is probably in the first column which would be the column 0 instead.

All just a guess though....
 
Back
Top