如何将ComboBox作为查询条件,且查询的条件为数据库中的某一列的值,在运行时在下拉列表中可以找到,怎样做,给出代码 。 如何将ComboBox作为查询条件,且查询的条件为数据库中的某一列的值,在运行时在下拉列表中可以找到,怎样做,给出代码 。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.getBindName(); } } //绑定公司名称 private void getBindName() { string sql = "select *from areacodetable"; SqlDataBase DB = new SqlDataBase(); DataSet ds; ds = DB.GetDS(sql); this.DropDownList2.DataSource = ds; this.DropDownList2.DataTextField = "areacodeName"; this.DropDownList2.DataValueField = "areacodeid"; this.DropDownList2.DataBind(); ListItem lt = new ListItem(); lt.Text = "请选择"; lt.Value = "00"; lt.Selected = true; this.DropDownList2.Items.Add(lt); } cSqlmob.getconn(); string str = "select u_Name from SH_Users"; cmb_Users.DataSource = sqlmob.getDataSet(str).Tables[0]; cmb_Users.DisplayMember = sqlmob.getDataSet(str).Tables[0].Columns[0].ColumnName; sqlmob.conn_close(); SqlDataBase DB = new SqlDataBase();是什么意思啊 SqlDataBase DB = new SqlDataBase();是创建一个database 用来做ComboBox的数据源我写的很清楚了啊,在Page_Load事件里面调用getBindName()方法,这样就行 了 string ConnectionString="DataSource=sky;user=system;password=manager;";//写连接串 OracleConnection conn=new OracleConnection(ConnectionString);//创建一个新连接 try { conn.Open(); OracleCommand cmd=conn.CreateCommand(); cmd.CommandText="select 名字 from 用户表";//在这儿写sql语句 OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象 while(odr.Read())//读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了 { this.comboBox.Items.Add(odr.GetValue(0).ToString()); } } catch(Exception ee) { MessageBox.Show(ee.Message); //如果有错误,输出错误信息 } finally { if(odr!=null) { odr.Close(); } if(conn.State==ConnectionState.Open) { conn.Close(); //关闭连接 } } 试试这个 private void Form1_Load(object sender, EventArgs e) { string ConnectionString = "Data Source=vigorss;user id=scott;password=tiger";//写连接串 OracleConnection conn = new OracleConnection(ConnectionString);//创建一个新连接 string sql="select distinct empno from emp"; try { conn.Open(); OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader odr = cmd.ExecuteReader();//在这儿写sql语句 OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象 while (odr.Read())//读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了 { this.cmbempno.Items.Add(odr.GetValue(0).ToString()); } } catch (Exception ee) { MessageBox.Show(ee.Message); //如果有错误,输出错误信息 } finally { if (conn.State == ConnectionState.Open) { conn.Close(); //关闭连接 } } }这样就行了 C#用DirectShow处理视频和音频问题 C#绘图放大缩小问题 事件对象转换问题。。 C# 对xml 添加节点 删除节点 关于封装datagrid 的问题 求指点移除和删除 请教一个问题??急 WPF,怎么创建一个实现Button的类的? 如何修改文件及文件夹的创建日期?在线等待,急..... 在使用TreeView怎样添加一个子项呢? TreeView1.Nodes.Add(tnTemp); asp.net中treeview使用方法 把窗体的边框设为 none 后,单开窗体,窗体还是闪烁一下显示边框,请问可以解决吗?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.getBindName();
}
}
//绑定公司名称
private void getBindName()
{
string sql = "select *from areacodetable";
SqlDataBase DB = new SqlDataBase();
DataSet ds;
ds = DB.GetDS(sql);
this.DropDownList2.DataSource = ds;
this.DropDownList2.DataTextField = "areacodeName";
this.DropDownList2.DataValueField = "areacodeid";
this.DropDownList2.DataBind();
ListItem lt = new ListItem();
lt.Text = "请选择";
lt.Value = "00";
lt.Selected = true;
this.DropDownList2.Items.Add(lt);
}
string str = "select u_Name from SH_Users";
cmb_Users.DataSource = sqlmob.getDataSet(str).Tables[0];
cmb_Users.DisplayMember = sqlmob.getDataSet(str).Tables[0].Columns[0].ColumnName;
sqlmob.conn_close();
是创建一个database 用来做ComboBox的数据源
我写的很清楚了啊,在Page_Load事件里面调用
getBindName()方法,这样就行 了
string ConnectionString="DataSource=sky;user=system;password=manager;";//写连接串
OracleConnection conn=new OracleConnection(ConnectionString);//创建一个新连接
try
{
conn.Open();
OracleCommand cmd=conn.CreateCommand();
cmd.CommandText="select 名字 from 用户表";//在这儿写sql语句 OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象
while(odr.Read())//读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了
{
this.comboBox.Items.Add(odr.GetValue(0).ToString());
}
}
catch(Exception ee)
{
MessageBox.Show(ee.Message); //如果有错误,输出错误信息
}
finally
{
if(odr!=null)
{
odr.Close();
}
if(conn.State==ConnectionState.Open)
{
conn.Close(); //关闭连接
}
}
试试这个
{
string ConnectionString = "Data Source=vigorss;user id=scott;password=tiger";//写连接串
OracleConnection conn = new OracleConnection(ConnectionString);//创建一个新连接
string sql="select distinct empno from emp";
try
{
conn.Open();
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataReader odr = cmd.ExecuteReader();//在这儿写sql语句 OracleDataReader odr=cmd.ExecuteReader();//创建一个OracleDateReader对象
while (odr.Read())//读取数据,如果odr.Read()返回为false的话,就说明到记录集的尾部了
{
this.cmbempno.Items.Add(odr.GetValue(0).ToString());
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message); //如果有错误,输出错误信息
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close(); //关闭连接
}
} }
这样就行了