有关连接acess数据库的问题
string StrSQL = "DELETE FROM 表1 WHERE ";
StrSQL += "表1 姓名= ' " + this.textBox1.Text + " ' ";
this.odbcCommand1.CommandText = StrSQL;
this.odbcCommand1.Connection = this.oleDbConnection1;
//打开数据库连接
this.oleDbConnection1.Open();
//执行SQL命令
this.odbcCommand1.ExecuteNonQuery();
//关闭连接
this.oleDbConnection1.Close();
//更新数据
this.dataSet1.Tables[ "表1 "].Rows[this.MyBind.Position].BeginEdit();
this.dataSet1.Tables[ "表1 "].Rows[this.MyBind.Position].EndEdit();
this.dataSet1.AcceptChanges();
this.oleDbDataAdapter1.Fill(this.dataSet1, "表1 ");
this.MyBind.Position = 0;
其中第四行这条语句出错:
this.odbcCommand1.Connection = this.oleDbConnection1;
系统报错为:无法将类型“System.Data.OleDb.OleDbConnection”隐式转换为“System.Data.Odbc.OdbcConnection” 请问怎么处理这样的情况??高手指教!
------解决方案--------------------错误原因
使用了oledb打开的连接
使用了odbc的command
解决方式
使用oledb的command就行
OleDbCommand cmd
------解决方案--------------------this.odbcCommand1.Connection = this.oleDbConnection1;
---------------
Command 换成 oleDbCommand ?
------解决方案--------------------ding !
同意flyin2006的
------解决方案--------------------用
OleDbCommand odbcCommand1 = new OleDbCommand(StrSQL ,oleDbConnection1);