对于Microsoft Access 2010 .ACCDB SQL连接字符串 [英] SQL connection string for microsoft access 2010 .accdb
问题描述
我做的使用WinForms和访问一个简单的登录表单2010数据库(.accdb)在C#。
I am doing a simple login form using winforms and access 2010 database (.accdb) in C#.
我有下面的代码,它似乎连接字符串是错的。我曾尝试搜索和发现.Jet是进入07?但是这似乎没有工作过。
我在数据库的业余(代码从MSDN简称)。 。我无法了解哪些我应该使用这个例子太
I have the following code and it seems that the connection string is wrong. I have tried searching and found that .Jet is for access 07?? but this doesnt seem to work too. i am an amateur at databases (code referred from msdn). I am having trouble understand which should i use for this example too.
访问表的名字:哈哈结果
access table name: haha
ID (PK) | password
-----------------------
1 | testing
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BC207\test.accdb");
System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand();
comm.CommandText = "SELECT HAHA(*) FROM password";
comm.CommandType = CommandType.Text;
comm.Connection = conn;
conn.Open();
Object returnValue = comm.ExecuteScalar();
conn.Close();
MessageBox.Show((string)returnValue);
编辑:表的名字是密码,我想要得到的值字段ID。
edited: the table's name is password, and the field that i want to get the value is ID.
SQL语句,我写的是: SELECT ID FROM密码
SQL statement i wrote it as : SELECT ID FROM password
和肯定,在该表作为主键只有一个字段只有一个记录。
and yes, only one record in only one field in the table as the primary key.
反正问题是,该程序在执行时第一个挂行结果
- >关键字不支持:供应商
anyway the problem is that the program hangs upon execution on the first line
-> Keyword not supported: 'provider'.
所以我想我有一个错误的连接字符串。
so i figured that I have a wrong connection string..
推荐答案
有关艾策斯数据库(.MDB,.ACCDB,等...),你想使用的的OleDbConnection ,不是的SqlConnection(SQL Server)的,就像这样:
For Acces databases (.mdb, .accdb, etc...), you want to use OleDbConnection, not SqlConnection (SQL Server), like this:
conn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BC207\test.accdb")
这篇关于对于Microsoft Access 2010 .ACCDB SQL连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!