DropDownList问题

fiten_z 2009-02-05 11:23:38
运行时出现错误,如果把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: {

...全文
56 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mike老羊 2009-02-05
  • 打赏
  • 举报
回复
depID 是Int类型吧?!
ljhcy99 2009-02-05
  • 打赏
  • 举报
回复
SelectedValue 是 string 类型的,看看你的 depID 类型。
xfreyes 2009-02-05
  • 打赏
  • 举报
回复
不是引号问题
xfreyes 2009-02-05
  • 打赏
  • 举报
回复
可能是
while (dr1.Read())
{
this.ListBox1.Items.Add(new ListItem(dr1.GetString(0),dr1.GetInt32(0).ToString()));
}

试试看
JaggerLee 2009-02-05
  • 打赏
  • 举报
回复
depID 估计你是 int 类型的
而你拼接的语句的DropDownList1.SelectedValue值外面包了单引号,在SQL中是 字符串类型

单引号去掉就行了
xray2005 2009-02-05
  • 打赏
  • 举报
回复
depID 是Int类型吧?!

string commstring1="select * from emp where depID="+int.Parse(this.DropDownList1.SelectedValue);
eynStudio 2009-02-05
  • 打赏
  • 举报
回复
会不会是DropDownList1.SelectedValue根本就没有select某个item。
用selectedValue一般要先判断是否有选择项。
hs1983 2009-02-05
  • 打赏
  • 举报
回复
数据类型问题吧

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧