运行时出现错误,如果把where depID='"+this.DropDownList1.SelectedValue+"'这段去掉就能正常运行
{
if(!Page.IsPostBack){
string connstring="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=department.mdb;";
string commstring="select * from TDdepartment";
   string commstring1="select * from emp where depID='"+this.DropDownList1.SelectedValue+"'"; OleDbConnection conn=new OleDbConnection(connstring);
OleDbCommand comm=new OleDbCommand(commstring,conn);
comm.Connection.Open();
dr=comm.ExecuteReader();
this.DropDownList1.DataSource=dr;
this.DropDownList1.DataTextField="depName";
this.DropDownList1.DataValueField="depID";
this.DropDownList1.DataBind();
            dr.Close();
            OleDbCommand comm1=new OleDbCommand(commstring1,conn);
dr1=comm1.ExecuteReader();
while (dr1.Read())
  {
this.ListBox1.Items.Add(new ListItem(dr1.GetString(1),dr1.GetInt32(0).ToString()));
  }
dr1.Close();


}
}提示错误如下:
--------------------------------------------------------------------------------
Server Error in '/shuju2' Application.
--------------------------------------------------------------------------------準則運算式的資料類型不符合。 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: 準則運算式的資料類型不符合。Source Error: 
Line 38:             dr.Close();
Line 39:             OleDbCommand comm1=new OleDbCommand(commstring1,conn);
Line 40:  dr1=comm1.ExecuteReader();
Line 41:  while (dr1.Read())
Line 42:    {
 

解决方案 »

  1.   

    会不会是DropDownList1.SelectedValue根本就没有select某个item。
    用selectedValue一般要先判断是否有选择项。
      

  2.   

    depID 是Int类型吧?!string commstring1="select * from emp where depID="+int.Parse(this.DropDownList1.SelectedValue); 
      

  3.   

    depID 估计你是 int 类型的
    而你拼接的语句的DropDownList1.SelectedValue值外面包了单引号,在SQL中是 字符串类型单引号去掉就行了
      

  4.   

    可能是
    while (dr1.Read()) 
      { 
    this.ListBox1.Items.Add(new ListItem(dr1.GetString(0),dr1.GetInt32(0).ToString())); 
      } 试试看
      

  5.   

    SelectedValue 是 string 类型的,看看你的 depID 类型。