Hello,
I am adapting this tutorial to my needs:
And I am receiving this error when it tries to take the Excel spreadsheet data and insert it into the SQL table:
System.InvalidCastException: Conversion from string "Percussion" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at Intra_Directors_ImportStudents.ImportIntoStudents(String FirstName, String LastName, Int32 GradYear, String ConcertInstrument, String MarchingInstrument, String JazzInstrument, String FSMASchoolID) in c:\inetpub\ 166
I don't understand why it is converting "Percussion" (which is the ConcertInstrument field) from a String to an Integer, because it is supposed to be a String.
Here is the vb code that calls the Insert function from my DataSet:
Here's the entire function... I've tried changing the Return Type to string, but that didn't work either.
Any help would be greatly appreciated.
Thanks!
...Josh
I am adapting this tutorial to my needs:
And I am receiving this error when it tries to take the Excel spreadsheet data and insert it into the SQL table:
System.InvalidCastException: Conversion from string "Percussion" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) at Intra_Directors_ImportStudents.ImportIntoStudents(String FirstName, String LastName, Int32 GradYear, String ConcertInstrument, String MarchingInstrument, String JazzInstrument, String FSMASchoolID) in c:\inetpub\ 166
I don't understand why it is converting "Percussion" (which is the ConcertInstrument field) from a String to an Integer, because it is supposed to be a String.
Here is the vb code that calls the Insert function from my DataSet:
Code:
' if Student ID is still 0, then the student doesn't already exist, so insert it into the table
If StudentID = 0 Then
' retrieve the identity key StudentID from the InsertStudentQuery Function:
StudentID = Convert.ToInt32(SSAdapter.InsertStudentQuery(FirstName, LastName, GradYear, ConcertInstrument, MarchingInstrument, JazzInstrument, FSMASchoolID))
LabelImport.Text = LabelImport.Text & _
"<font color=green>Member Imported: " & _
" ID: " & StudentID & " " & FirstName & " " & _
LastName & " ConcertInstrument: " & ConcertInstrument & ".</font><br>"
End If
Return StudentID
Catch ex As Exception
LabelImport.Text = LabelImport.Text & "<font color=red>" & _
ex.ToString & "</font><br>"
Return 0
End Try
Here's the entire function... I've tried changing the Return Type to string, but that didn't work either.
Code:
Protected Function ImportIntoStudents(ByVal FirstName As String, _
ByVal LastName As String, ByVal GradYear As Integer, _
ByVal ConcertInstrument As String, ByVal MarchingInstrument As String, ByVal JazzInstrument As String, _
ByVal FSMASchoolID As String) As Integer
' make sure values don't exceed column limits
FirstName = Left(LastName, 50)
LastName = Left(FirstName, 50)
GradYear = Left(GradYear, 4)
ConcertInstrument = Left(ConcertInstrument, 10)
MarchingInstrument = Left(MarchingInstrument, 10)
JazzInstrument = Left(JazzInstrument, 10)
FSMASchoolID = Left(FSMASchoolID, 10)
Dim StudentID As Integer = 0
Try
Dim SSAdapter As New StudentImportDataSetTableAdapters.tblStudentsTableAdapter
Dim SSDataTable As StudentImportDataSet.tblStudentsDataTable = Nothing
SSDataTable = SSAdapter.GetStudentsByFullNameSchool(FirstName, LastName, FSMASchoolID)
' see if the Student already exists in the table, if not insert it
If Not SSDataTable Is Nothing Then
If SSDataTable.Rows.Count > 0 Then
If Not SSDataTable(0).StudentID = Nothing Then
StudentID = SSDataTable(0).StudentID
LabelImport.Text = LabelImport.Text & _
"<font color=blue>Member Found, Not Imported: " & _
" ID: " & StudentID & " " & FirstName & " " & LastName & ".</font><br/>"
End If
End If
End If
' if Student ID is still 0, then the student doesn't already exist, so insert it into the table
If StudentID = 0 Then
' retrieve the identity key StudentID from the InsertStudentQuery Function:
StudentID = Convert.ToInt32(SSAdapter.InsertStudentQuery(FirstName, LastName, GradYear, ConcertInstrument, MarchingInstrument, JazzInstrument, FSMASchoolID))
LabelImport.Text = LabelImport.Text & _
"<font color=green>Member Imported: " & _
" ID: " & StudentID & " " & FirstName & " " & _
LastName & " ConcertInstrument: " & ConcertInstrument & ".</font><br>"
End If
Return StudentID
Catch ex As Exception
LabelImport.Text = LabelImport.Text & "<font color=red>" & _
ex.ToString & "</font><br>"
Return 0
End Try
End Function
Any help would be greatly appreciated.
Thanks!
...Josh