2014-01-17 41 views
1
OleDbConnection con = new OleDbConnection(constr); 

     con.Open(); 

     // // code for project name- id starts 
     string Sql_project_name = "select customer_name, customer_mobile1 from tb_customer"; 

     OleDbCommand cmd = new OleDbCommand(Sql_project_name, con); 

     OleDbDataReader DR = cmd.ExecuteReader(); 
     DataTable table = new DataTable(); 
     table.Load(DR); 

     //begin adding line 
     DataRow row = table.NewRow(); 
     row["customer_name"] = "Select Customer Details"; 

     table.Rows.InsertAt(row, 0); 
     // end adding a line 


     combo_project_name.DataSource = table; 


     combo_project_name.DisplayMember = "customer_name"; 

     combo_project_name.Text = "Select Customer Details"; 

在這段代碼我顯示CUSTOMER_NAME正被從數據庫中取出......但我想說明它customer_mobile_number與CUSTOMER_NAME和customer_mobile之間用逗號相同組合框。 ..how我能實現這個....顯示組合框中兩個選項在C#.NET

回答

1

更改您的查詢作爲

string Sql_project_name = 
select customer_name + ' , ' + customer_mobile1 as CombinedName from tb_customer` 

,改變你的組合框顯示成員作爲

combo_project_name.DisplayMember = "CombinedName"; 
0

試試這個:

OleDbConnection con = new OleDbConnection(constr); 

    con.Open(); 

    // // code for project name- id starts 
    string Sql_project_name = "select customer_name + ', ' + customer_mobile1 as customer_name_and_mobile from tb_customer"; 

    OleDbCommand cmd = new OleDbCommand(Sql_project_name, con); 

    OleDbDataReader DR = cmd.ExecuteReader(); 
    DataTable table = new DataTable(); 
    table.Load(DR); 

    //begin adding line 
    DataRow row = table.NewRow(); 
    row["customer_name"] = "Select Customer Details"; 

    table.Rows.InsertAt(row, 0); 
    // end adding a line 

    combo_project_name.DataSource = table; 
    combo_project_name.DisplayMember = "customer_name_and_mobile"; 
    combo_project_name.Text = "Select Customer Details"; 
0

您可以嘗試填充組合框的另一種方法。而不是使用數據源屬性,手動循環查詢數據並將它們添加到組合框中。

combo_project_name.Items.Clear(); 
for (x = 0; x <= y; x++) { 
combo_project_name.Items.Add(customer_name + ", " + customer_mobile1); 
} 

,也可以使用SQL本身這樣的合併結果...

SELECT customer_name + ', ' + customer_mobile1 as NewFieldName FROM tb_customer; 
相關問題