I keep getting 'Invalid attempt to read when data is present' at line retObj.DatabaseID = DR.GetString(0)
I checked the connection str: works fine
I checked the SQL str: work fine
VB Code:
Public Class NetDatabase ...'properties hidden Public Function GetDetails(ByVal DatabaseID As String) As NetDatabase Dim retObj As New NetDatabase Dim DR As SqlDataReader Dim dataAcc As New DataAccess Try DR = dataAcc.GetData("SELECT * FROM [database] where DatabaseID ='" & DatabaseID & "'") retObj.DatabaseID = DR.GetString(0) retObj.DatabaseName = DR.GetString(1) retObj.Domestic = DR.GetString(2) retObj.Connectionstring = DR.GetString(3) Return retObj Catch ex As Exception MsgBox(ex.ToString) End Try End Function End Class Private Class DataAccess Dim mConnectionString As String = "SERVER=192.168.0.1;DATABASE=DEV_NETUSERDB;UID=sa;PWD=pwd;" Private ReadOnly Property ConnectionString() As String Get Return mConnectionString End Get End Property Public Function GetData(ByVal SQLstr As String) As SqlDataReader Dim sqlDR As SqlDataReader Dim DA As New DataAccess Try Dim sqlCn As New SqlConnection(DA.mConnectionString) Dim sqlCmd As New SqlCommand(SQLstr, sqlCn) sqlCn.Open() 'open connection with sql string If UCase(Left(SQLstr, 6) = "SELECT") Then sqlDR = sqlCmd.ExecuteReader While sqlDR.Read() sqlDR.Close() 'Why? Cos MSDN Says:you cannot retrieve output parameters until after you call Close. Return sqlDR End While Else sqlCmd.ExecuteNonQuery() End If sqlCmd.Connection.Close() Catch ex As Exception MsgBox(ex.ToString) End Try End Function End Class
Has someone out there have any idea why?




Reply With Quote