如何连接到LibreOffice基础数据库?

问题描述 投票:0回答:1

我希望这不是转发,但我还没有找到答案。如何在C#中连接到LibreOfficeBase-database?我没有MS Access,这就是我只有Libre的原因。到目前为止,这是我写的:

private void add_Click(object sender, EventArgs e)
{
    OleDbConnection con = new OleDbConnection();
    OleDbCommand cmd = new OleDbCommand();
    OleDbDataReader reader;

    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +  
    "Data Source=C:\\Users\\user\\Desktop\\data.odb;";

    cmd.Connection = con;
    cmd.CommandText = "INSERT INTO data(name, age)" +
        "VALUES('" + FamilyName.Text + "', '" + Age.Text +"')";
    try
    {
        con.Open();
        reader = cmd.ExecuteReader();
        reader.Close();
        con.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

我的数据库名为data.odb,当然它不起作用,因为此方法适用于.accdb文件。我该怎么办.odb文件?

c# database base
1个回答
1
投票

odb是openoffice数据库。有一个用于处理odb文件的MySQL连接器,请参见https://wiki.openoffice.org/wiki/Database/Drivers/MySQL_Native/1.0

您也可以通过OpenOffice文档https://wiki.openoffice.org/wiki/Database#Developer说明如何连接到MS Access https://wiki.openoffice.org/wiki/Connecting_to_Microsoft_Access

© www.soinside.com 2019 - 2024. All rights reserved.