2014-03-28 78 views
0

我已经创建了一个可以与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 

回答

1

创建通过ODBC访问数据库, Windows自带的。 您也可以使用其他可用的数据库(例如MySQL,Firebird,SQLite等),如果安装它的话不一定会让您的客户端花费任何东西(或者,对于某些数据库,如果将它包含在您的安装中他们)。

使用MS Office COM自动化要求将MS Office产品安装在运行自动化的机器上。 有第三方代码库可用自己的代码替换该功能,这意味着您的应用可以创建自己的Access兼容文件。但是,您的用户仍然需要Access才能使用它们

相关问题