I am using ASP.NET 2.0. We are using a stored procedure w/ a pivot query that returns the names of positions and hours worked per project but depending on the dates passed into the stored procedure the same positions do not get returned - people get promoted, leaving, etc. Since the pivot query only returns positions (columns) that have relevant data that matches the date criteria, the number of columns returned is variable and so are the column names.
I can get the column names using SQLDataReader.GetName but how do I get the rest of the data? I am used to specifying the column names in my functions to return data and completely clueless as to how to do this without them.
Right now code is this:
Public Function GetData(ByVal StartDate As Date, ByVal EndDate As Date) As List(Of String)
Using conn As New SqlConnection(ConnectionVarName)
Using com As New SqlCommand("storedProcName", conn)
com.Parameters.Add(New SqlParameter("@ParamName1", DataSqlDbType.DateTime)).Value = StartDate
com.Parameters.Add(New SqlParameter("@ParamName2", DataSqlDbType.DateTime)).Value = EndDate
com.CommandType = Data.CommandType.StoredProcedure
conn.Open()
Using dr As SqlDataReader = com.ExecuteReader()
Dim ColumnCount As Integer = dr.FieldCount
Dim ColumnName As String
For i As Integer = 0 to ColumnCount - 1
ColumnName = dr.GetName(i).ToString()
Next
End Using
End Using
End Using
End Fuction
End Function
I can get the column names using SQLDataReader.GetName but how do I get the rest of the data? I am used to specifying the column names in my functions to return data and completely clueless as to how to do this without them.
Right now code is this:
Public Function GetData(ByVal StartDate As Date, ByVal EndDate As Date) As List(Of String)
Using conn As New SqlConnection(ConnectionVarName)
Using com As New SqlCommand("storedProcName", conn)
com.Parameters.Add(New SqlParameter("@ParamName1", DataSqlDbType.DateTime)).Value = StartDate
com.Parameters.Add(New SqlParameter("@ParamName2", DataSqlDbType.DateTime)).Value = EndDate
com.CommandType = Data.CommandType.StoredProcedure
conn.Open()
Using dr As SqlDataReader = com.ExecuteReader()
Dim ColumnCount As Integer = dr.FieldCount
Dim ColumnName As String
For i As Integer = 0 to ColumnCount - 1
ColumnName = dr.GetName(i).ToString()
Next
End Using
End Using
End Using
End Fuction
End Function