“不支持关键字:提供商”连接到 VS08 上的 Access 数据库
我正在尝试将 DataGridView 连接到 Visual Studio 2008 上的 access 2000 数据库。
我不断收到“不支持关键字:提供程序”错误,因为我对 .Net 上的 Windows 开发相当陌生,我不知道是否我我做得对。
这是代码:
Try
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Contingencia\Carga_sap.mdb;User Id=admin;Password=;"
Dim strQuery As String = "SELECT ..."
Dim dataAdapter = New SqlDataAdapter(strQuery, strConn)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
dataAdapter.Fill(table)
bsLista.DataSource = table
GridListado.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
提前致谢
编辑:我只需要将数据适配器更改为 OLE:
Dim dataAdapter = New OleDbDataAdapter(strQuery, strConn)
I'm trying to connect a DataGridView to an access 2000 database on Visual Studio 2008.
I keep getting the "Keyword not supported: provider" error, as I'm fairly new to windows development on .Net I don't know if I'm doing it right.
Here's the code:
Try
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Contingencia\Carga_sap.mdb;User Id=admin;Password=;"
Dim strQuery As String = "SELECT ..."
Dim dataAdapter = New SqlDataAdapter(strQuery, strConn)
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
dataAdapter.Fill(table)
bsLista.DataSource = table
GridListado.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Thanks in advance
EDIT: I just needed to change the Data Adapter to OLE:
Dim dataAdapter = New OleDbDataAdapter(strQuery, strConn)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用
OleDbDataAdapter
而不是SqlDataAdapter
。它尝试将连接字符串读取为 SQL Server 连接字符串。You should be using
OleDbDataAdapter
instead ofSqlDataAdapter
. It's trying to read the connection string as a SQL Server connection string.