Combobox databinding showing system.data.datarowview

后端 未结 7 1544
猫巷女王i
猫巷女王i 2021-01-01 00:08

I am binding combobox with datasource, displaymember, valuemember. It is working fine in my computer but it is not working in clients pc. Following is my source code:

<
相关标签:
7条回答
  • 2021-01-01 00:33

    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 ##

    0 讨论(0)
提交回复
热议问题