I need urgent help please!!!!
This is my problem:
I want to connect to a Access database with VB.Net.
Here is my imports:
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Collections
Imports System.ComponentModel
Here is my connection string:
Public pDB As New OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source='F:\relayMaster.mdb';Jet OLEDB:Engine Type=5;Provider='Microsoft.Jet.OLEDB.4.0';Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1")
Public pDataAdapt As New OleDbDataAdapter
Here is my code where i want to access the database:
Private Sub GetTodayScd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
pDSet1.Clear()
pDSet2.Clear()
Dim switchOnceSQL As String
switchOnceSQL = "SELECT switchOnce.day, switchOnce.month, switchOnce.year, switchOnce.hour, switchOnce.min, switchOnce.port, switchOnce.state "
switchOnceSQL &= "FROM(switchOnce) "
switchOnceSQL &= "WHERE(((switchOnce.day) = "
switchOnceSQL &= Now().ToString("dd")
switchOnceSQL &= ") And ((switchOnce.month) = "
switchOnceSQL &= Now().ToString("MM")
switchOnceSQL &= ") And ((switchOnce.year) = "
switchOnceSQL &= Now().ToString("yyyy")
switchOnceSQL &= ")) ORDER BY switchOnce.day, switchOnce.month, switchOnce.year, switchOnce.hour, switchOnce.min, switchOnce.port;"
Try
pDataAdapt.SelectCommand = New OleDbCommand(switchOnceSQL, pDB)
pDataAdapt.Fill(pDSet1, "OnceOff")
Catch ex As OleDbException
MessageBox.Show("Connection to Database Failed", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Dim scheduleSQL As String
scheduleSQL = "SELECT schedule.day, 0 AS [month], 0 AS [year], schedule.hour, schedule.min, schedule.port, schedule.state "
scheduleSQL &= "FROM(schedule) "
scheduleSQL &= "WHERE (((schedule.day)="
scheduleSQL &= Now().DayOfWeek()
scheduleSQL &= ")) ORDER BY schedule.day, schedule.hour, schedule.min, schedule.port;"
Try
pDataAdapt.SelectCommand = New OleDbCommand(scheduleSQL, pDB)
pDataAdapt.Fill(pDSet2, "Schd")
Catch ex As OleDbException
MessageBox.Show("Connection to Database Failed", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
schDGrid1.SetDataBinding(pDSet1, "OnceOff")
schDGrid2.SetDataBinding(pDSet2, "Schd")
End Sub
and last, here is my error:
Connection to Database Failed
I am stil new to programming and need all the help I can get. Tx a mill :cry: