F
fniles
I am using .Net 2003 and querying a SQL Server 2000 database.
I read the database in a loop, but on every iteration I set the SQLCommand
to new, set it, execute it, dispose and set it to nothing.
Is there any way so that I do not have to do that ? In VB6, I can set a
recordset to new once, set it and execute it within the loop, and close it
after the loop.
Thanks.
Dim m_cmdSQLT As SqlClient.SqlCommand
Dim m_drSQLTop As SqlClient.SqlDataReader
Do While bContinue
sSQL = "GetPacketDataTop"
m_cmdSQLT = New SqlClient.SqlCommand
With m_cmdSQLT
.Connection = TickServerAdoCon
.CommandType = CommandType.StoredProcedure
.CommandText = sSQL
End With
m_cmdSQLT.Parameters.Add("@sContract", SqlDbType.VarChar, 8)
m_cmdSQLT.Parameters.Add("@dTime1", SqlDbType.DateTime, 8)
m_cmdSQLT.Parameters.Add("@dTime2", SqlDbType.DateTime, 8)
m_cmdSQLT.Parameters("@sContract").Value = txtSymbol.Text
m_cmdSQLT.Parameters("@dTime1").Value = dTime1
m_cmdSQLT.Parameters("@dTime2").Value = dtime2
m_drSQLTop = m_cmdSQLT.ExecuteReader()
If m_drSQLTop.Read Then sOpen = "" & m_drSQLTop("PACKET_DATA")
m_drSQLTop.Close()
m_cmdSQLT.Dispose()
m_cmdSQLT = Nothing
:
dTime1 = DateAdd(DateInterval.Minute, 1, dTime1)
dtime2 = DateAdd(DateInterval.Minute, 1, dTime1)
If DateDiff(DateInterval.Minute, dLast, dTime1) >= 1 Then
bContinue = False
End If
Loop
I read the database in a loop, but on every iteration I set the SQLCommand
to new, set it, execute it, dispose and set it to nothing.
Is there any way so that I do not have to do that ? In VB6, I can set a
recordset to new once, set it and execute it within the loop, and close it
after the loop.
Thanks.
Dim m_cmdSQLT As SqlClient.SqlCommand
Dim m_drSQLTop As SqlClient.SqlDataReader
Do While bContinue
sSQL = "GetPacketDataTop"
m_cmdSQLT = New SqlClient.SqlCommand
With m_cmdSQLT
.Connection = TickServerAdoCon
.CommandType = CommandType.StoredProcedure
.CommandText = sSQL
End With
m_cmdSQLT.Parameters.Add("@sContract", SqlDbType.VarChar, 8)
m_cmdSQLT.Parameters.Add("@dTime1", SqlDbType.DateTime, 8)
m_cmdSQLT.Parameters.Add("@dTime2", SqlDbType.DateTime, 8)
m_cmdSQLT.Parameters("@sContract").Value = txtSymbol.Text
m_cmdSQLT.Parameters("@dTime1").Value = dTime1
m_cmdSQLT.Parameters("@dTime2").Value = dtime2
m_drSQLTop = m_cmdSQLT.ExecuteReader()
If m_drSQLTop.Read Then sOpen = "" & m_drSQLTop("PACKET_DATA")
m_drSQLTop.Close()
m_cmdSQLT.Dispose()
m_cmdSQLT = Nothing
:
dTime1 = DateAdd(DateInterval.Minute, 1, dTime1)
dtime2 = DateAdd(DateInterval.Minute, 1, dTime1)
If DateDiff(DateInterval.Minute, dLast, dTime1) >= 1 Then
bContinue = False
End If
Loop