Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone there.

I would like to know on how to get the data(GradeLevel) from my table (tblClass) and put it inside my combo box using C#. I am new about this language. Hoping anyone can help me :) Thanks in advance :)
Posted

1 solution

In simple it could be like:
C#
using (SqlConnection sqlConnection = new SqlConnection("connstring"))
{
    SqlCommand sqlCmd = new SqlCommand("SELECT * FROM tblClass", sqlConnection);
    sqlConnection.Open();
    SqlDataReader sqlReader = sqlCmd.ExecuteReader();

    while (sqlReader.Read())
    {
        cbDoctor.Items.Add(sqlReader["name"].ToString());
    }

    sqlReader.Close();
}

Remember it's a format, not the whole code.Also see:
populate combo box in c#[^]
 
Share this answer
 
Comments
ridoy 29-Dec-14 7:16am    
Downvoters please leave a comment here, so that i can improve the solution and hence it can help the OP.
DarkDreamer08 29-Dec-14 7:39am    
What do you mean by "name" at your code? is it the field name that I want to load at my combo box?
ridoy 29-Dec-14 7:42am    
Yes that's a field name or property name of your database table that you want to load in your combobox.
DarkDreamer08 29-Dec-14 7:46am    
Thank you! it is working!!! Hope you will help me again if I have another question to ask about C#. I am just a beginner here :) I think I will post another question later Haha XD Merry Christmas :)
ridoy 29-Dec-14 8:40am    
welcome. feel free to ask about learning.Merry Christmas :)

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