select语句中的类型品配的问题

Eweek 2005-05-11 10:13:07
一个combobox绑定的数据源的类型是varchar,一个datagrid绑定表table1的一字段tableID类型也是varchar类型,我的datagrid绑定的select语句是:select * from table1 where table1.tableID=combobox.SelectText.
调试时系统指示我的sqlDataAdapter.Fill()错误;
我先修改select语句:select * from table1 结果运行正确.所以错误在where中.我不知道怎么就错了???高手低手给看看啊.
...全文
96 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eweek 2005-05-12
  • 打赏
  • 举报
回复
我的是winform~~
syfsz 2005-05-12
  • 打赏
  • 举报
回复
你的DropDownList数据绑定的不对吧?另外把你选择出来的值最好Trim() 一下
Eweek 2005-05-11
  • 打赏
  • 举报
回复
我再试试吧~~
xiao_haozi 2005-05-11
  • 打赏
  • 举报
回复
string select = DropDownList1.SelectedItem.Text.Trim();
string user_information = "select User_id,User_Name,Company,Telephone from User_inform where favour like '%"+select+"%'";
SqlConnection myConnection = new SqlConnection(WebForm1.myconnect);
SqlDataAdapter myCommand = new SqlDataAdapter (user_information,myConnection);
myConnection.Open();
DataSet ds = new DataSet();
myCommand.Fill(ds,"User_inform");
DataGrid1.DataSource=ds.Tables["User_inform"].DefaultView;
DataGrid1.DataBind();
myConnection.Close();
这是我写的一段程序,你自己参考一下,你在页面上加个button,然后用button除法这个事件,老实说我也刚刚开始用asp.net,comboBox1_SelectedIndexChanged这个东西我吃不准
xiao_haozi 2005-05-11
  • 打赏
  • 举报
回复
你代码贴的多一点,这样看不清楚
Eweek 2005-05-11
  • 打赏
  • 举报
回复
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;
string reselect = "select * from table where tabel.tableid='"+comboBox1.SelectedText.Trim()+"'";
//MessageBox.Show(reselect);
sqlDataAdapter1=new SqlDataAdapter(reselect,sqlConnection1);
sqlDataAdapter1.Fill(userDS1,"table");
dataGrid1.SetDataBinding(userDS1,"table");
}
这里不会有错吧^^
Eweek 2005-05-11
  • 打赏
  • 举报
回复
combobox选择的值如果table1.tableID有,则datagrid应该显示的是符合table1.tableID='"+combobox.SelectText.trim()+"的值
如果table1.tableID没有combobox选中的值,那么datagrid也显示空值.
现在不关选择哪个,datagrid就是不变,显示的是table的全部值
xiao_haozi 2005-05-11
  • 打赏
  • 举报
回复
?????select * from table1 where table1.tableID='"+combobox.SelectText.trim()+这句你显示的是空??
njuhuangmy 2005-05-11
  • 打赏
  • 举报
回复
select * from table1 where tableID like % || combobox.SelectText || %
Eweek 2005-05-11
  • 打赏
  • 举报
回复
MessageBox.Show: select * from table where tableid='' 怎么成空值了?
xiao_haozi 2005-05-11
  • 打赏
  • 举报
回复
select * from table1 where table1.tableID='"+combobox.SelectText.trim()+"'试试~!
Eweek 2005-05-11
  • 打赏
  • 举报
回复
:(怎么用MessageBox.Show跟踪?我把sql 语句写进去了 结果显示的是我的select语句:)
Eweek 2005-05-11
  • 打赏
  • 举报
回复
id中有对应的记录(1000和1001),当我在combobox中选择1000时,结果中还是有1001的记录
kv4000 2005-05-11
  • 打赏
  • 举报
回复
或者MessageBox.Show("你的sql语句")跟踪一下看看 sql语句内容是否正确?
kv4000 2005-05-11
  • 打赏
  • 举报
回复
看你combox中的id是否在table1中有此条对应的记录?
Eweek 2005-05-11
  • 打赏
  • 举报
回复
回复kv4000:
我刚试了,运行没错,但是结果显示不对,当我在combobox选择一个值时,datagrid显示空,
kv4000 2005-05-11
  • 打赏
  • 举报
回复
select * from table1 where table1.tableID=combobox.SelectText 改为

select * from table1 where table1.tableID='"+combobox.SelectText+"'

110,539

社区成员

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

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

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