c# - Populate 3 combobox from same table but use filter in all 3 tables -


i have windows application having 3 combobox. username, prepared by, authorized by. want name of employees in user name whereas in prepared , authorized want selected names same table. have assigned roles in employee table integer value , fired stroed procedure. cannot populate combobox

sql:

emp table: create table emp1 (     employee_id int constraint pk_employee_id_employee primary key not null,     un_id varchar(10) constraint uk_un_id_employee unique not null,     fname varchar(20) not null,     lname varchar(20) not null,     roles int not null )  stored procedure: alter proc rolecombo (     @roles int   ) begin select * emp1 roles<@roles end 

c# code:

 private void form1_load(object sender, eventargs e)         {             con.open();             adp = new sqldataadapter(cmd);             cmd.connection = con;             cmd.commandtype = commandtype.storedprocedure;             cmd.commandtext = "rolecombo";             cmd.parameters.addwithvalue("@roles",combobox3.selectedvalue);             adp.fill(dsautho, "emp1");             combobox3.datasource = dsautho.tables["emp1"];             combobox3.displaymember = "fname";             combobox3.valuemember = "employee_id";             combobox3.selectedindex = -1;             con.close(); } 

try sample code:

public static dataset downdatabind() {     try     {         sqlconnection conn = new sqlconnection("data source=s1b01689;initial catalog=cosmosdb;user id=sa;password=nttdata123");         conn.open();          sqldataadapter adapter = new sqldataadapter("select id,categname cm_categories",conn);         dataset ds = new dataset();          adapter.fill(ds);          adapter.dispose();          conn.close();          return ds;     }     catch (exception exp)     {         string s = exp.message.tostring();         return null;     } }  private void form1_load(object sender, eventargs e) {     try     {         dataset ds = downdatabind();         combobox1.datasource = ds.tables[0];// use tables[0] instead of table name         combobox1.valuemember = "id";         combobox1.displaymember = "categname";         combobox1.selectedindex = -1;              }     catch (exception exp)     {         messagebox.show(exp.message);     } } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -