在C#连接OOLEDB数据库的时候,出现了“多步oledb多步操作产生错,如果可能有可能,检查每个oledb状态值“

运行是没有错误,在检验连接是否成功时出现了问。代码如下:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("用户名或密码为空!");
}
else
try
{
string ConStr = "provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password=‘+ this.textBox2.Text + ’;User=‘ + this.textBox1.Text +’; Data source =‘登陆账号.mdb’"; //生成数据库连接字符串
OleDbConnection oleCon = new OleDbConnection(ConStr);
oleCon.Open();
//定义OleDbConnection对象实例并连接数据库
OleDbCommand olecom = new OleDbCommand("select * from denglu", oleCon);
DataSet ds = new DataSet();//定义DataSet实例
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
//连接数据表格,显示数据
oleCon.Close();
}
catch (Exception ey)
{
MessageBox.Show(ey.Message);

}
}

我是初学者,谢谢帮助!

第1个回答  2012-04-07
string ConStr = "provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password=‘+ this.textBox2.Text + ’;User=‘ + this.textBox1.Text +’; Data source =‘登陆账号.mdb’"; //生成数据库连接字符串
OleDbConnection oleCon = new OleDbConnection(ConStr); //定义OleDbConnection对象
OleCon.Open();
OleDbDataAdapter da=new OleDbDataAdapter("select * from denglu", oleCon);
DataSet ds = new DataSet();//定义DataSet实例
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;//连接数据表格,显示数据
oleCon.Close();
第2个回答  2012-04-07
试试:
OleDbConnection oleCon = new OleDbConnection(ConStr);
try{
String sql="select * from denglu";
OleDbDataAdapter da=new OleDbDataAdapter(sql,oleCon);
DataTable dt=new DataTable();
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}
catch(Exception err){throw err}
finally{
if(oleCon .Status!=ConnectionStatus.Closed){ oleCon.Close();}
}本回答被网友采纳
第3个回答  2012-04-08
你的代码中根本就没有填充DATASET操作。
相似回答