dataGridView利用bindingSource和bindingNavigator控件显示数据

来源:互联网 发布:软件银行集团股票 编辑:程序博客网 时间:2024/05/22 07:40
 private void showData()
        {
            try
            {
                OracleConnection conn = new OracleConnection(ConnectionString);
                conn.Open();
              OracleDataAdapter   da = new OracleDataAdapter(string.Format("SELECT Inventory_No,CK_no,CK_name,Start_Time,InventoryMans,Insert_Time,"
                  + "Other From T_BJ_Inventory Where ProfitOrLoss is null And Inventory_No like '%{0}%' order by Inventory_No", Inventory_No.Text), conn); 
                DataSet   ds = new DataSet();
                da.Fill(ds);
                bindingSource1.DataSource = ds.Tables[0];
                this.bindingNavigator1.BindingSource = bindingSource1;
                this.dataGridView1.DataSource = bindingSource1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {

                conn.Dispose();
                conn.Close();
               ds.Dispose();

            }

        }

da.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].ToString();

原创粉丝点击