我已經創建了一個可以與MS Access 2010(.accdb)擴展一起使用的程序。該方案是完全正常工作。Visual Studio應用程序的數據庫訪問問題
的問題是:
當程序被安裝到一個沒有MS Office的安裝在另一臺PC上,然後,在程序中定義的異常返回連接錯誤。當然是的,因爲如果沒有安裝Office,程序無法讀取(.accdb)文件。
需求的解決方案:
有什麼辦法來導入這個(.ACCDB),以讀取和修改。或者,當應用程序安裝到任何非辦公室安裝的PC上時,是否還有其他簡單的解決方案?
我的程序代碼演示是:
連接字符串:
Imports SpeechLib
Imports System.IO
Module MdlIPray5ve
Public con As OleDb.OleDbConnection
Public cmd As OleDb.OleDbCommand
Public sql As String
Public speaker As New SpVoice
Public Function connection() As String
Try
connection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=azan_time.accdb; Persist Security Info=False;"
Catch ex As Exception
MessageBox.Show("Could not connect to the Database. Check your Connection!")
End Try
End Function
東西訪問數據庫:
Private Sub UpdateAlarmTone()
Try
Dim cmdText = "UPDATE alarm_tone SET subhi= @subhi1, zuhur [email protected], aser = @aser1, megrib = @megrib1, isha = @isha1"
Using con As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(cmdText, con)
con.Open()
cmd.Parameters.AddWithValue("@subhi1", txtSubhi.Text)
cmd.Parameters.AddWithValue("@zuhur1", txtZuhur.Text)
cmd.Parameters.AddWithValue("@aser1", txtAser.Text)
cmd.Parameters.AddWithValue("@megrib1", txtMegrib.Text)
cmd.Parameters.AddWithValue("@isha1", txtIsha.Text)
Dim infor As String
infor = cmd.ExecuteNonQuery
If (infor > 0) Then
MsgBox("Alarm Tone record updated successfuly")
Else
MsgBox("Update failed!")
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show("There is a problem with your connection!")
End Try
End Sub