Hi
Firstly, you must choose what is your DBMS type (Access or oracle or sql server)
Secondly, you must work in three steps:
1)Select your data from the table in your database
2)put your selected data in a list (List<string> object)
3)Now you can fill the [DropdownList] by items in your List<string>
As example,I used SQL server as DBMS and I have in my database a [Table] named program contains two columns [Id,Name] :
1) Firstly,I'll fill the List<string> by using static Method :
static public List<string> SelectPrograms(List<string> programs)
{
string ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection connect = new SqlConnection(ConnectionString);
string query = "select program_name from Program;";
SqlCommand command = new SqlCommand(query, connect);
connect.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
string x;
while (reader.Read())
{
x = Convert.ToString(reader[0]);
programs.Add(x);
}
}
finally
{
reader.Close();
connect.Close();
}
return programs;
}
2)Now I'll use the last method after I take a List<string> variable
List<string> program = new List<string>();
program = [Put_ClassName].SelectPrograms(program);
3)Finally, I'll Fill my [DropdownList]
for (int i = 0; i < program.Count; i++)
{
DropDownList_ProgramName.Items.Add(program[i]);
}
Good lock....