111,126
社区成员
发帖
与我相关
我的任务
分享
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(); //关闭连接
}
}
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);
}