T
tjonsek
I am converting an ASP page to asp.net. In this application, a user can
enter a list of numbers, separated by commas. The relationship involved
is 1 to M and I never know how many different numbers the user will
enter.
I am getting a 'specified cast not valid' error. While I'm not 100% it
is the array, This is the block of code that I have narrowed down to
causing the problem.
I've spent some time reading on the net about the differences in arrays
in vb.net and am wondering if the split function I am using isn't the
best route to go.
Please give any pointers about arrays or suggestions for what might
cause that specific error message.
In old ASP, my code looked like this:
dim woPrefix
dim aryWO
dim I
woPrefix = "ASHC"
aryWO = split(session("WO"),",",-1)
set rst1 = cmd1.Execute()
For I = 0 to UBound(aryWO)
if session("flgType") = "e" or Instr(1,session("WO"),"ASHC") then
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & aryWO(I) & "') "
else
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & woPrefix & aryWO(I) & "') "
end if
Next
This is what I have in my .NET app:
Dim woPrefix As String
Dim aryWO As Array
Dim I As Integer
woPrefix = "ASHC"
aryWO = Split(txtWO.Text, ",", -1)
SqlSelectCommand1.CommandType = CommandType.Text
SqlSelectCommand1.CommandText = "Delete from
contractOutWO where ID ='" & lblID.Text & "'"
SqlSelectCommand1.ExecuteNonQuery()
For I = 0 To UBound(aryWO)
If ddlCOType.SelectedValue = "E" Or InStr(1,
txtWO.Text, "ASHC") Then
SqlSelectCommand1.CommandText =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & aryWO(I) & "') "
Else
SqlSelectCommand1 =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & woPrefix & aryWO(I) & "') "
End If
If Len(SqlSelectCommand1.CommandText) > 0 Then
SqlSelectCommand1.ExecuteNonQuery()
End If
Next
enter a list of numbers, separated by commas. The relationship involved
is 1 to M and I never know how many different numbers the user will
enter.
I am getting a 'specified cast not valid' error. While I'm not 100% it
is the array, This is the block of code that I have narrowed down to
causing the problem.
I've spent some time reading on the net about the differences in arrays
in vb.net and am wondering if the split function I am using isn't the
best route to go.
Please give any pointers about arrays or suggestions for what might
cause that specific error message.
In old ASP, my code looked like this:
dim woPrefix
dim aryWO
dim I
woPrefix = "ASHC"
aryWO = split(session("WO"),",",-1)
set rst1 = cmd1.Execute()
For I = 0 to UBound(aryWO)
if session("flgType") = "e" or Instr(1,session("WO"),"ASHC") then
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & aryWO(I) & "') "
else
sqlCmd = sqlCmd + "Insert into contractOutWO Values(" &
session("ID") & ",'" & woPrefix & aryWO(I) & "') "
end if
Next
This is what I have in my .NET app:
Dim woPrefix As String
Dim aryWO As Array
Dim I As Integer
woPrefix = "ASHC"
aryWO = Split(txtWO.Text, ",", -1)
SqlSelectCommand1.CommandType = CommandType.Text
SqlSelectCommand1.CommandText = "Delete from
contractOutWO where ID ='" & lblID.Text & "'"
SqlSelectCommand1.ExecuteNonQuery()
For I = 0 To UBound(aryWO)
If ddlCOType.SelectedValue = "E" Or InStr(1,
txtWO.Text, "ASHC") Then
SqlSelectCommand1.CommandText =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & aryWO(I) & "') "
Else
SqlSelectCommand1 =
SqlSelectCommand1.CommandText + "Insert into contractOutWO Values('" &
lblID.Text & "','" & woPrefix & aryWO(I) & "') "
End If
If Len(SqlSelectCommand1.CommandText) > 0 Then
SqlSelectCommand1.ExecuteNonQuery()
End If
Next