Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i am making school website in which i want that when new class add in database then auto fill that class in combobox of student registration form during Form load.

here is my code but it doesnot work.
can any body help me that problem?
thanks in advance.
C#
protected void Page_Load(object sender, EventArgs e)
       {

           SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Final Project\FinalProject\FinalProject\App_Data\Record.mdf;Integrated Security=True;User Instance=True");
           conn.Open();
           SqlCommand sc = new SqlCommand("select ClassName from SchoolClass", conn);
           SqlDataReader reader;

           reader = sc.ExecuteReader();
           DataTable dt = new DataTable();
           dt.Columns.Add("ClassName", typeof(string));

           dt.Load(reader);


           drpclass.SelectedValue = "ClassName";
           drpclass.DataSource = dt;

           conn.Close();

       }
Posted
Updated 7-Mar-13 3:59am
v2
Comments
[no name] 7-Mar-13 9:57am    
Please format your code so that it is readable and then explain what "does not work" means.
ZurdoDev 7-Mar-13 9:59am    
What exactly does not work?
Richard C Bishop 7-Mar-13 11:13am    
If you are using ASP.Net, then you need to call the DataBind() method after setting the datasource. That is the only thing I can see without you providing more details.

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