运行时出现错误,如果把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: {
{
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: {
解决方案 »
- Post登陆某网站,出现401,求解决
- C# excel导出过程中 手动再打开一个excel时 报错0x800AC472 急!!
- 请问如何调用webservice中自定义类中的方法和带参数构造函数?
- 怎样读取QQ对话框的消息
- 求问DX的RepositoryItemColorEdit
- 现在WinForm程序还能登录进aspx页面吗?
- 怎么用C#得到一个进程的路径!!
- Windows API 取另一程序文本框值的问题
- 已知图片的名字,怎么在Properties.Resources找到?
- C# WinForm 添加Windows Media Player 控件调试出现未能加载文件或程序集Interop.WMPLib
- 请教各位:开发这样的小程序需要多长时间。
- C# WinForm 打包问题,急!!!
用selectedValue一般要先判断是否有选择项。
而你拼接的语句的DropDownList1.SelectedValue值外面包了单引号,在SQL中是 字符串类型单引号去掉就行了
while (dr1.Read())
{
this.ListBox1.Items.Add(new ListItem(dr1.GetString(0),dr1.GetInt32(0).ToString()));
} 试试看