主题:用户代码未处理 System.Data.OleDb.OleDbException
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
tr.Show();
if (e.Node.Level==2)
{
string str = "select [Typeid] from [OutcomeList] where [Typename]='" + e.Node.Text + "'";
// "') union select Typeid from OutcomeList where (Typename='" + e.Node.Text+"');";
//MessageBox.Show(str,"notes");
tr.define(str);
}
}
public void define(string s)
{
c = new Conn();
OleDbCommand Comm = new OleDbCommand(s,c.createconn());
MessageBox.Show(s, "notes");
OleDbDataReader dr=Comm.ExecuteReader();
while (dr.Read())
{
this.label1.Text = dr.GetString(0);
}
dr.Close();
Comm.Connection.Close();
}
class Conn
{
public OleDbConnection createconn()
{
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=data.mdb");
conn.Open();
return conn;
}
}
可以连到数据库,在 OleDbDataReader dr=Comm.ExecuteReader();
出现异常 + $exception {"语法错误 (操作符丢失) 在查询表达式 '[Typeid] from [OutcomeList] where [Typename]='食品'' 中。"} System.Exception {System.Data.OleDb.OleDbException}
请帮帮我啊
{
tr.Show();
if (e.Node.Level==2)
{
string str = "select [Typeid] from [OutcomeList] where [Typename]='" + e.Node.Text + "'";
// "') union select Typeid from OutcomeList where (Typename='" + e.Node.Text+"');";
//MessageBox.Show(str,"notes");
tr.define(str);
}
}
public void define(string s)
{
c = new Conn();
OleDbCommand Comm = new OleDbCommand(s,c.createconn());
MessageBox.Show(s, "notes");
OleDbDataReader dr=Comm.ExecuteReader();
while (dr.Read())
{
this.label1.Text = dr.GetString(0);
}
dr.Close();
Comm.Connection.Close();
}
class Conn
{
public OleDbConnection createconn()
{
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=data.mdb");
conn.Open();
return conn;
}
}
可以连到数据库,在 OleDbDataReader dr=Comm.ExecuteReader();
出现异常 + $exception {"语法错误 (操作符丢失) 在查询表达式 '[Typeid] from [OutcomeList] where [Typename]='食品'' 中。"} System.Exception {System.Data.OleDb.OleDbException}
请帮帮我啊