Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I want to fill datagridview combobox column but This code it's not running properly,
this code generate every rows for every text of combobox value, it's not running properly.

Please help me.
C#
SqlConnection con = new SqlConnection(cnString1);//connection to the your database
                SqlCommand cmd = new SqlCommand("fetchUUSLaminateName", con);//create a SQL command object by passing name of the stored procedure and database connection 
                cmd.CommandType = CommandType.StoredProcedure;//set command object command type to stored procedure type

                SqlDataAdapter adp = new SqlDataAdapter(cmd);//create SQL data adapter with command object
                DataTable dt = new DataTable();//create a data table to hold result of the command
                //DataGridViewComboBoxColumn dgvcmb = new DataGridViewComboBoxColumn();

                if (con.State == ConnectionState.Closed)//check whether connection to database is close or not
                    con.Open();//if connection is close then only open the connection
                adp.Fill(dt);//data table fill with data by calling the fill method of data adapter object
                if (dt.Rows.Count > 0)//check whether data table contain any row or not
                {
                    
                    LamiName.DataSource = dt;
                    LamiName.ValueMember = "UUSLaminateName";
                    LamiName.DisplayMember = "UUSLaminateName";
                    dgvUUSKreationPriceCalculator.DataSource = dt;
                    if (con.State == ConnectionState.Open)
                        con.Close();
                }
Posted
Updated 15-Oct-13 19:25pm
v2
Comments
Ank_ush 16-Oct-13 1:47am    
What you actually want to do now ? Plz clear the question (Write the question in detail).
Shubh Agrahari 16-Oct-13 2:09am    
and what do you mean by "it's not running properly."...share issues what error showing it.......that can help us to help you
tarunsitlani 16-Oct-13 3:01am    
set DataPropertyName for the column
LamiName.DataPropertyName = "UUSLaminateName";

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