本文介绍了从组合框中选择值,根据该值,数据将从数据库加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码是来自Usertype组合框的选择值

组合框包含像(hr,production,executive)这样的值。



如果有人选择hr,下一个组合框将从sql数据库加载与hr相关的所有员工



组合框名称= UserType_CMBbox,UserName_CMBbox





the code is for select value from Usertype combo box
combo box contain values like (hr, production, executive) like that.

if someone select hr, next combo box will load all employees related to hr from sql database

Combo box names = UserType_CMBbox , UserName_CMBbox


{
            String Usertype = UserType_CMBbox.SelectedValue.ToString();
            //Select User Type from user type Combo box

            UserName_CMBbox.Items.Clear();
            DataSet ds = new DataSet();
            ds.Clear();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=Unicella_Data;Integrated Security=True";
            con.Open();
            SqlDataAdapter adpi = new SqlDataAdapter("Select distinct User_Name from Login_Table Where User_Type='" + Usertype + "'", con);
            adpi.Fill(ds);
            UserName_CMBbox.DataSource = ds.Tables[0];
            UserName_CMBbox.DisplayMember = "User_Name";
            con.Close();
        }





问题是数据无法加载到其他组合框中



the problem is data will not load into the other combo box

推荐答案

  String Usertype = UserType_CMBbox.SelectedValue.ToString();
   //Select User Type from user type Combo box

   UserName_CMBbox.DataSource = null;
   DataSet ds = new DataSet();
   SqlConnection con = new SqlConnection();
   con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=Unicella_Data;Integrated Security=True";
   con.Open();
   SqlDataAdapter adpi = new SqlDataAdapter("Select distinct User_Name from Login_Table Where User_Type='" + Usertype + "'", con);
   adpi.Fill(ds);
   UserName_CMBbox.DataSource = ds.Tables[0];
   UserName_CMBbox.DisplayMember = "User_Name";
   con.Close();







我希望这会对你有所帮助。



感谢

Mohan G




I hope this will help you.

Thank's
Mohan G


这篇关于从组合框中选择值,根据该值,数据将从数据库加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:15