尊敬的各位前辈:
小弟现在遇到一个对于初学者棘手的问题,问题具体是这样的。我有一个远端数据库 61.188.*.* 里面有个表dzyd,表里面有两个字段为userID , userName , userClass 。我现在需要做一个下来菜单的通过userClass来查询显示userID,userName这两个字段在DataGrid里面显示,DataGrid的ID为sj_sourceDataGrid。请问我要如何实现?最好能给出一些关键代码作为提示,谢谢大侠的帮助小弟不胜感激。
小弟现在遇到一个对于初学者棘手的问题,问题具体是这样的。我有一个远端数据库 61.188.*.* 里面有个表dzyd,表里面有两个字段为userID , userName , userClass 。我现在需要做一个下来菜单的通过userClass来查询显示userID,userName这两个字段在DataGrid里面显示,DataGrid的ID为sj_sourceDataGrid。请问我要如何实现?最好能给出一些关键代码作为提示,谢谢大侠的帮助小弟不胜感激。
string sql = "select * from userClass where userName='"+comboBox1.Text+"'";
将DropDownList的AutoPostBack属性设置成true
执行下面的SQL语句,你将会得到一个DataTable或DataSet
string sql="select userID,userName from dzyd where userClass='"+ddlClass.SelectedItem.Text.Trim();
然后将DataGrid的数据源设置成得到的DataTable或DataSet
sj_sourceDataGrid.DataSource=dt(或ds)
sj_sourceDataGrid.Bind();
这样就OK了啊
不过要想做得更好一点的话,就用一下Ajax技术
引用 3 楼 caohongliang2008 的回复:
C# code
将DropDownList的AutoPostBack属性设置成true
执行下面的SQL语句,你将会得到一个DataTable或DataSet
string sql="select userID,userName from dzyd where userClass='"+ddlClass.SelectedItem.Text.Trim();
然后将DataGrid的数据源设置成得到的DataTable或DataSet
sj_sourceDataGrid.DataSource=dt(或ds)
sj_sourceDataGrid.Bind();
这样就OK了啊
正解!