数据库MS Access的连接问题 [英] connection problem with database MS Access
本文介绍了数据库MS Access的连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在运行时使用MS Access在Visual Studio 2008中使用C#Windows程序在运行时出现错误(初始化字符串的格式不符合从索引0开始的规范.)
Hi All,
I m using C# windows program in Visual Studio 2008 with MS Access at run time I m getting error (Format of the initialization string does not conform to specification starting at index 0.) bellow given the program
public partial class partmaster : Form
{
private OdbcConnection con = new OdbcConnection();
private basecon obj = new basecon(); //basecon is a class file
private void partmaster_Load(object sender, EventArgs e)
{
grid();
}
private void grid()
{
dgvPartMaster.Columns.Clear();
DataGridViewTextBoxColumn dgvCol = new DataGridViewTextBoxColumn();
con.ConnectionString = Microsoft.VisualBasic.Strings.Trim(obj.connection().ToString()); // error is showing (Format of the initialization string does not conform to specification starting at index 0.)
con.Open();
string qry;
推荐答案
尝试更改此行:
try changing this line:
private OdbcConnection con = new OdbcConnection();
对此:
to this:
private OleDbConnection con = new OleDbConnection();
您可以在app.config中这样调用您的mdb文件:
and you can call your mdb file like this in your app.config:
<connectionStrings>
<add name="myconn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}App_Data\mydb.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
希望对您有所帮助:)
hope it helps :)
这篇关于数据库MS Access的连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文