When i get SelectedItem in combobox return System.Data.DataRowView

后端 未结 5 641
暖寄归人
暖寄归人 2020-12-21 14:26

this is a function for retrive two field in sql to combobox : Code :

public void FillCmbKala()
    {
        cmbKala.Items.Clear();
                 


        
5条回答
  •  生来不讨喜
    2020-12-21 14:45

    THIS WILL DEFINITELY HELP TO YOU

    on the load Event you want to Just Write this code

    onformload()
    {
    
         cmb_dept.Items.Clear();
    
         SqlConnection conn = new SqlConnection(@"DATA SOURCE=(localdb)\MSSQLLocalDB;INTEGRATED SECURITY=true;INITIAL CATALOG=EMPLOYEE;");
    
         conn.Open();
    
         SqlCommand command = new SqlCommand("select dept_id, dept_name from department", conn);
    
         SqlDataAdapter adapter = new SqlDataAdapter(command);
    
         DataSet ds = new DataSet();
    
         adapter.Fill(ds);
    
         cmb_dept.ValueMember = "dept_id";
    
         cmb_dept.DisplayMember = "dept_name";
    
         cmb_dept.DataSource = ds.Tables[0];
    
     }
    

    try using Use the code where you want to access the values........

    string dept = cmb_dept.Text; MessageBox.Show("val=" + dept);
    YOUR combobox.text = System.Data.DataRowView Will be Solved ##
    

提交回复
热议问题