Click here to Skip to main content
15,885,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to access data from two tabels to a single dropdown list...I need help
Posted
Comments
george4986 13-Sep-14 0:44am    
use union all/union query if implimenting in backend.
use merge function of datatable for front end.
BharatPrajapati212 13-Sep-14 1:08am    
please clear what data you want in your dropdownlist and in which format you would like to insert.
MuhammadUSman1 13-Sep-14 1:51am    
Which data you want to show, you can use join union etc

1 solution

Try this solution I hope it may help you
C#
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(@"Connection String");
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.System.Data.DataTable dt = new System.Data.protected void Page_Load(object sender, EventArgs e)
{
        con.Open();
        da = new System.Data.SqlClient.SqlDataAdapter
        ("SELECT Name FROM Namedata UNION SELECT City FROM Citydata", con);
        da.Fill(dt);
        
        foreach(System.Data.DataRow D in dt.Rows)
        {
            DropDownList1.Items.Add(D[0].ToString());
        }
        con.Close();
}
 
Share this answer
 

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