Data displayed wrong in ASP .NET DataGrid
I am currently maintaining an ASP .NET application that connects to a SQL Server 2000 database. Everything has worked fine (as far as I know) until now.
When I open a view in SQL Server, all data is returned correctly. When I open this same view with a DataReader or DataAdapter (tried both to see if one or the other was a problem), I am able to view the correct results as well. The problem occurs when I bind the resulting datareader or datatable to a datagrid. I have a column that should have information in it (as it shows up in SQL Server or the Watch Window in Visual Studio), but the DataGrid displays the column as empty.
There are no errors that occur: The app uses On Error GoTo, so when I debug I have break points at every function and subroutine. I have also walked through the debug step-by-step. There are no problems at all, and like I said before, I can view the table and datareader contents in the watch window and it shows up correctly.
Here is the Databind code:
Dim objGF As New GeneralFunctions
Dim ReturnedResults As New DataTable
ReturnedResults = objGF.GetDataSet(Global.gConn, strSQL) ' Returns a datatable from a dataadapter
If ReturnedResults.Rows.Count < 1 Then
'turn off datagrid
OurDataGrid.Visible = False
lblResults.Text = "No Entries found in the Database."
Else
'bind data
lblResults.Text = ""
OurDataGrid.Visible = True
OurDataGrid.DataSource = ReturnedResults 'setup <asp:datagrid> tag
OurDataGrid.DataBind() 'attach data from db to asp datagrid
End If
Here's the function for filling the DataSet
Public Function GetDataSet(ByVal Conn As String, ByVal QueryStr As String) As DataTable
On Error GoTo ErrHand
'setup SQL db connection
Dim OurConnection As New OleDbConnection 'connection
Dim OurCommand As OleDbCommand 'sql command
Dim OurDataAdapter As New OleDbDataAdapter 'results from sql statement
Dim dsResults As New DataTable
OurConnection = New OleDbConnection(Conn) 'set sql string to Conn
OurCommand = New OleDbCommand(QueryStr, OurConnection) 'setup sql command
OurDataAdapter.SelectCommand = OurCommand
OurDataAdapter.Fill(dsResults)
Return dsResults
ExitFunct:
If Not OurCommand Is Nothing Then
OurCommand = Nothing
End If
If Not OurDataAdapter Is Nothing Then
OurDataAdapter = Nothing
End If
If Not OurConnection Is Nothing Then
OurConnection = Nothing
End If
Exit Function
ErrHand:
Resume ExitFunct
End Function
Any help will be appreciated. I have searched Google and Microsoft for any possible known issues with the DataGrid displaying contents incorrectly, but with no results.
Thanks.
|