Hi
I am trying to split multiple arrays and insert them into SQL Server.
From my query string I receive the following Sport.aspx?ReaderID=A1B5A0F5C4E4A1B5A0F5C4E4&DataID=11B6C56A90B645B6C56A90B6,10 Oct 2010 13:15:20,|22B6C56A90B645B6C56A90B6,10 Oct 2010 14:15:26,|&Msg=04
What I need to do is split the pipe delimited field into MyTagID and Clock as DateTime. The I need to loop tought the DataID field and insert in each row the ReaderID,TagID and Clock. The Msg I get will only be returned to sender as confimation.
Here is my code thus far. I tried to insert a loop but the loop were infinite.
Imports System.Data.Sql
Imports System.Data.SqlClient
Partial Class Sport
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
insertValue()
End Sub
Private Sub insertValue()
Dim sqlConn As New SqlConnection
Dim strConnection As String = ""
Dim MyReaderID As String = ""
Dim MyCustom As String = ""
Dim MyMsg As Int64
Dim MyTagArray() As String
Dim MyDataArray() As String
Dim TagID As String = ""
Dim MyTagID As String = ""
Dim DateTimeS As String = ""
Dim DateTime As datetime = "1 Jan 1990 00:00:00"
Dim Antenna As String = ""
Dim i As Integer
MyReaderID = Request("ReaderID").trim
MyMsg = Request("Msg").trim
MyTagID = Request("TagID")
If mytagID.length > 0 Then
TagID = ""
MyDataArray = Request("TagID").Split("|")
For i = 0 To Ubound(MyDataArray) - 1
Next
MyTagarray = Request("TagID").Split(",")
For i = 0 To Ubound(MyTagArray) - 1
TagID = TagID & MyTagArray(i) & ","
Next
TagID = MyTagArray(0).trim
DateTimeS = (MyTagArray(1).trim)
If DateTimeS = "" Then
DateTimeS = "1 Jan 1990 00:00:00"
End If
Else
DateTimeS = "1 Jan 1990 00:00:00"
End If
DateTime = CDate(DateTimeS)
Try
strConnection = "Data Source=SOURCE;Initial Catalog=DB;Persist Security Info=True;User ID=USER;Password=PWD"
sqlConn = New SqlConnection(strConnection)
Dim InsertCommand As New SqlCommand("INSERT INTO Readings(ReaderID, TagID, Clock) VALUES ( '" & myReaderID & "', '" & TagID & "', '" & DateTime & "')", sqlConn)
sqlConn.Open()
InsertCommand.ExecuteNonQuery()
sqlConn.Close()
Catch ex As Exception
Response.Write(ex)
End Try
Response.Write("Success" & MyMsg & "<br>")
End Sub
End Class
Thank you