Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to bind dropdownlist in disconnected mode
Posted

C#
DataTable table = new DataTable();
           cmd = new SqlCommand();
           cmd.CommandText = "GetEmployee";
           cmd.CommandType = CommandType.StoredProcedure;

           table = dbConn.ExecuteQuery(cmd);
           ddlEmp.DataSource = table;
           ddlEmp.DataValueField = "DeptId";
           ddlEmp.DataTextField = "DeptName";
           ddlEmp.DataBind();
 
Share this answer
 
Comments
srishti_ 13-Aug-12 6:26am    
thanks ur solution was helpful for me
Santhosh Kumar Jayaraman 13-Aug-12 6:32am    
Can you mark it as accepted answer? SO that others will know
srishti_ 13-Aug-12 6:52am    
i did
Santhosh Kumar Jayaraman 13-Aug-12 6:52am    
thanks
try
{
sqlconnection con=new sqlconnection("Data Source=.; Initial Catalog=database name;uid=sa; pwd=password");
con.Open();
sqlcommand cmd = new OleDbCommand("select distinct(prod_Name) from purchase" , con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error...."+ex.Message);
}
 
Share this answer
 
Comments
srishti_ 11-Aug-12 7:26am    
i am asking in disconnected mode this solution is for connected mode.
Shambhoo kumar 11-Aug-12 7:39am    
ok ok......
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=cmcdb;Integrated Security=True");
        con.Open();
       SqlCommand cmd = new SqlCommand("select userid from logins ", con);
       SqlDataReader dr = cmd.ExecuteReader();
       while (dr.Read())
       {

           DropDownList1.Items.Add(dr["userid"].ToString());
       }
 
Share this answer
 
Comments
srishti_ 13-Aug-12 6:27am    
i am asking in disconnected mode.
Deepak Kr Choudhary 18-Aug-12 6:23am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900