klharding
Member
I have 2 tables, one table to list labels for data and another table that holds the data. I am creating a URL post with all of the elements. In the first function below I am reading all of the records from gns_ListColumns into an array. Then in the second function I am reading records from the appointments table and creating a string containing records from both tables. The System.IndexOfOutRangeException is happening on the second function on the line
It happens on the fifth column for "email". I am wondering if the string is hitting some kind of limit? I am sure it is something silly that I am missing, but I cannot figure it out.
VB.NET:
strURL += x & "=" & results(x).ToString() & "&"
VB.NET:
Private Function GetColumnNames()
Dim con As New SqlConnection(strConString)
Dim cmd As New SqlCommand("sp_GetColumnNames", con)
Dim results As SqlDataReader = Nothing
cmd.CommandType = CommandType.StoredProcedure
Dim columnnames As New List(Of String)()
Try
con.Open()
results = cmd.ExecuteReader
If results.HasRows Then
Do While results.Read
columnnames.Add(results("column_name").ToString())
Loop
End If
Catch ex As Exception
Messagebox.Show("GetColumnNames Error :" & DateAndTime.Now.ToString & " " & ex.ToString)
Finally
results.Close()
con.Close()
cmd.Dispose()
End Try
Return columnnames
End Function
VB.NET:
Private Sub GetRecords()
Dim con As New SqlConnection(strConString)
Dim cmd As New SqlCommand("sp_GetAppts", con)
Dim results As SqlDataReader = Nothing
cmd.CommandType = CommandType.StoredProcedure
Dim strApptPost As String = ConfigurationManager.AppSettings("ApptURLPost")
Dim strURL As String = String.Empty
Dim strGMFID As String = ConfigurationManager.AppSettings("GMFID")
Dim lead_id As Long = 0
Try
con.Open()
results = cmd.ExecuteReader
If results.HasRows Then
Do While results.Read
strURL = "?gmfid=" & strGMFID & "&form_id=consult_form&"
For Each x As String In GetColumnNames()
If x <> "lead_type" Then
strURL += x & "=" & results(x).ToString() & "&"
End If
Next
strURL = strURL.Substring(0, strURL.Length - 1)
TextBox1.Text += DateAndTime.Now & " URL: " & strApptPost & strURL & vbCrLf & vbCrLf
Loop
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
results.Close()
con.Close()
cmd.Dispose()
End Try