Anthony Githae
Кроме того, вам необходимо создать экземпляры команд, адаптеров и соединений из правильного пространства имен Данные.Для oledb
Смотрите выдержки из рабочего решения ниже ( .. не полный класс)
Public Class ClientLogicOdbc
Private DataBaseMessage As String
Private CmdConnect As System.Data.OleDb.OleDbConnection
Private CmdKPIList As System.Data.OleDb.OleDbCommand
Private DaTable As System.Data.OleDb.OleDbDataAdapter
Private TbKPIList As New System.Data.DataTable
Private TbKPIRow As System.Data.DataRow
Public Sub New()
Client_Data_Logged = New ClientData
DbConnectivity = DatabaseConnectivity.NotConnected
ConnString = ReadConnectionSetting("CompanyConnectionOleDb")
Call Connect()
End Sub
Private Sub Connect()
Try
CmdConnect = New System.Data.OleDb.OleDbConnection(ConnString)
CmdKPIList = New System.Data.OleDb.OleDbCommand()
CmdConnect.ConnectionString = ConnString
CmdConnect.Open()
DbConnectivity = DatabaseConnectivity.Connected
Catch ex As Exception
Me.LocalException = ex
Call RaiseErrorMessage(ex.Message, ex)
DbConnectivity = DatabaseConnectivity.Faulted
Debug.Print(ex.Message)
End Try
End Sub
Public Function Company_File_Exists(ByVal ReportListing As ClientData) As Boolean
Dim Found As Boolean = False
Dim DatabaseMessage As String
TbKPIList = New Data.DataTable
If DbConnectivity = DatabaseConnectivity.Connected Then
Try
DatabaseMessage = "Select dbo_Company_Files.Imported From dbo_Company_Files where dbo_Company_Files.Filename='" & ReportListing.name & "' and dbo_Company_Files.startTime=#" & ReportListing.startTime.ToString("yyyy-MM-dd hh:mm:ss") & "# and dbo_Company_Files.EndTime=#" & ReportListing.endTime.ToString("yyyy-MM-dd hh:mm:ss") & "# ;"
DaTable = New Data.OleDb.OleDbDataAdapter(DatabaseMessage, CmdConnect)
DaTable.Fill(TbKPIList)
TbKPIList.TableName = "dbo_Company_Files"
If TbKPIList.Rows.Count > 0 Then
Found = True
End If
Catch ex As Exception
LocalException = ex
Finally
If Not TbKPIList Is Nothing Then
TbKPIList.Clear()
TbKPIList = Nothing
End If
If Not DaTable Is Nothing Then
DaTable.Dispose()
DaTable = Nothing
End If
End Try
End If
Return Found
End Function
Public Function ReadConnectionSetting(ByVal key As String) As String
Dim result As String = ""
Dim ConnStringSetting As System.Configuration.ConnectionStringSettings
Try
Dim app_Conn_Settings As System.Configuration.ConnectionStringSettingsCollection =
System.Configuration.ConfigurationManager.ConnectionStrings
ConnStringSetting = app_Conn_Settings(key)
If IsNothing(ConnStringSetting) Then
result = ""
Else
result = ConnStringSetting.ConnectionString
End If
Catch ex As System.Configuration.ConfigurationErrorsException
End Try
Return result
End Function
End Class
CHill60
Знаете ли вы, что вы можете добавить информацию в свой пост, используя ссылку "улучшить решение" на вашем решении? Это предпочтительный подход, а не размещение нескольких решений одного вопроса (Что может привести к путанице, если один из них будет поднят/опущен, и они появятся не в той последовательности)