# combox绑定oracle查询的数据集(列)

# combox绑定oracle查询的数据集(列)

上一篇 /下一篇  2012-02-28 19:03:17 / 个人分类:c#

private void Form1_Load(object sender, EventArgs e)
        {

            OracleConnection con1 = new OracleConnection(" Data Source=orcl;User id=scott; Password=system;");//oracleconnection类隶属于命名空间system.data.oracleclient
            
           
            OracleCommand oc1 = new OracleCommand("select loc as newloc  from dept", con1);
            OracleDataAdapter da = new OracleDataAdapter(oc1);
            DataSet ds1 = new DataSet();
            oda.Fill(ds1);

            //dataGridView1.DataSource = ds1.Tables[0];

            统计出列表中记录条数 tables.rows.count
            //this.Text = ds1.Tables[0].Rows.Count.ToString();

            //for (int i=0; i < ds1.Tables[0].Rows.Count; i++)
            //{
            //    //向 combox添加子项items.add,dataset.tables.rows[行索引][列名字],此列名字对应oraclecommand中 sql的列名
            //    comboBox1.Items.Add(ds1.Tables[0].Rows[i]["newloc"]);
            //}

            //comboBox1.DataSource = ds1.Tables[0].Columns["newloc"];
            //combox绑定 数据库表查询数据集不用定位到每个列,和操作datagridview一样,定位到tables即可
            comboBox1.DataSource = ds1.Tables[0];
            //displaymember是展现给客户看的
            comboBox1.DisplayMember = "居住地";
            //valuemember为真正数据库中的列(或者sql的列或别名)
            comboBox1.ValueMember = "newloc";
        }
 
   private void loadns() 
        {
            try
            {
                SqlConnection con = Db.DbLink();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = selns;
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    this.comboBox3.Items.AddRange(new object[] { reader["nsmc"] });
                }
                reader.Close();
                con.Close();
            }
            catch
            {
            }
            finally { 
                
            }
           
        }

    
        //加载数据到datagrivew
        private void ref3()
        {
            SqlConnection con = Db.DbLink();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlDataAdapter adp = new SqlDataAdapter(selnr, con);
            adp.Fill(ds, "dt");
            BindingSource bds = new BindingSource(ds, "dt");
            this.dataGridView1.DataSource = bds;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值