Hallo Leute,
Ich habe mir ein Beispielprogramm heruntergeladen wo mit C# auf eine Access-Datenbank zugegriffen wird.
Im Beispiel wird eine .mdb Accessdatei verwendet, jedoch möchte ich eine .accdb verwenden.
Nachdem ich die mdb in accdb abgespeichert habe und den Pfad im Programm angepasst habe erschien folgende Meldung:
OleDbException was unhandled. (mit Verweis auf Zeile bookConn.Open() )
Nicht erkennbares Datenbankformat. C:\Test\book.accdb
Wie kann ich eine .accdb Datei verwenden ?
Danke für eure Hilfe
Ich habe mir ein Beispielprogramm heruntergeladen wo mit C# auf eine Access-Datenbank zugegriffen wird.
Im Beispiel wird eine .mdb Accessdatei verwendet, jedoch möchte ich eine .accdb verwenden.
Nachdem ich die mdb in accdb abgespeichert habe und den Pfad im Programm angepasst habe erschien folgende Meldung:
OleDbException was unhandled. (mit Verweis auf Zeile bookConn.Open() )
Nicht erkennbares Datenbankformat. C:\Test\book.accdb
Wie kann ich eine .accdb Datei verwenden ?
Danke für eure Hilfe
C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.OleDb;
- namespace TutorialConnectToAccessDB
- {
- public partial class FormMain : Form
- {
- private OleDbConnection bookConn;
- private OleDbCommand oleDbCmd = new OleDbCommand();
- //parameter from mdsaputra.udl
- private String connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=book.accdb;Persist Security Info=False";
- public FormMain()
- {
- //create connection using parameter from mdsaputra.udl
- bookConn = new OleDbConnection(connParam);
- InitializeComponent();
- }
- private void buttonInsert_Click(object sender, EventArgs e)
- {
- bookConn.Open();
- oleDbCmd.Connection = bookConn;
- oleDbCmd.CommandText = "insert into book (bookName, description) values ('" + this.textBoxBookName.Text + "','" + this.textBoxDescription.Text + "');";
- int temp = oleDbCmd.ExecuteNonQuery();
- if (temp > 0)
- {
- textBoxBookName.Text = null;
- textBoxDescription.Text = null;
- MessageBox.Show("Record Successfuly Added");
- }
- else
- {
- MessageBox.Show("Record Fail to Added");
- }
- bookConn.Close();
- }
- }