Looping SQL Question

Leeus

Well-known member
Joined
Dec 23, 2002
Messages
50
Code:
        Dim connstring As String = "data source=DBSERVER;initial catalog=FastTrack;integrated security=SSPI;persist security info=False;workstation id=LEEUS;packet size=4096"

        Dim sqlcon As New SqlConnection(connstring)
        Dim i As Integer
        Dim arr() As Integer
        Dim cmdsql As New SqlCommand()

        Dim dr As SqlDataReader

        For i = 0 To 7
            sqlcon.Open()
            cmdsql.CommandText = "select count(*) as counted from support where DateDiff(""d"",dateclosed,getdate()-" & i & ") = 0"
            cmdsql.CommandText = CommandType.Text
            cmdsql.Connection = sqlcon


            dr = cmdsql.ExecuteReader
            Do While dr.Read
                arr(i) = dr.Item("counted")
            Loop
            dr.Close()
            Label1.Text += arr(i)

            sqlcon.Close()
        Next i

I keep getting ExecuteReader: Connection property has not been initialized.
And am I going about this in the right way!???
 
Back
Top