Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
How can load all table in dataset from sql database in C#??
Posted
Comments
Thanks7872 16-Oct-13 3:42am    
What have you tried so far?
sankmahesh 16-Oct-13 4:16am    
I want to load in DropDownList all tables from specified DataBase?

my Code given below

da = new SqlDataAdapter("SELECT * FROM Emp_Details", SqlCon);
da1 = new SqlDataAdapter("SELECT * FROM Prod_Details", SqlCon);
da.Fill(ds, "Emp_Details");
da1.Fill(ds, "Prod_Details");

foreach (DataTable Dtta in ds.Tables)
{
ddlConfig.Items.Add(Dtta.TableName);
}

in here i loaded 2 specified tables only.

i want to load all Tables
ranukamadushan 16-Oct-13 3:54am    
can you be more specific with your question?
sankmahesh 16-Oct-13 4:16am    
I want to load in DropDownList all tables from specified DataBase?

my Code given below

da = new SqlDataAdapter("SELECT * FROM Emp_Details", SqlCon);
da1 = new SqlDataAdapter("SELECT * FROM Prod_Details", SqlCon);
da.Fill(ds, "Emp_Details");
da1.Fill(ds, "Prod_Details");

foreach (DataTable Dtta in ds.Tables)
{
ddlConfig.Items.Add(Dtta.TableName);
}

in here i loaded 2 specified tables only.

i want to load all Tables

Create a stored procedure including all the sql select queries.

SQL
create procedure testProc
as
begin

select Name from tblEmpMaster
select eId from tblLeave

end


and then add that to a single data adapter & use it as u want.

C#
private void button11_Click(object sender, EventArgs e)
        {
            connectDb DBC = new connectDb();
            SqlConnection con = DBC.connectToLocalDb();
            con.Open();
            SqlCommand cmd = new SqlCommand("testProc", con);
            cmd.CommandType = CommandType.StoredProcedure;
            DataTable dt = new DataTable();

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            adapter.Fill(dt);
            comboBox4.DataSource = dt;
            comboBox4.DisplayMember = "Name";

            con.Close();
        }
 
Share this answer
 
v2
Comments
sankmahesh 16-Oct-13 5:20am    
Thankyou ranukamadushan,

i already work that...

but i dont know what are the tables available the database..

when i select any database from webconfig then automatically load all table. i mainly need the table name.
ranukamadushan 16-Oct-13 5:25am    
type this in sql;

SELECT name FROM sys.Tables

this query will give you all the table names which are available in particular database
sankmahesh 16-Oct-13 6:31am    
Thankyou ranukamadushan,

I want table with data.

in your comment i load all table and again i fetch data from DataBase.

it's possible for single fetch from DataBase
ranukamadushan 16-Oct-13 6:41am    
Please read below articles, i think those will help you.

http://stackoverflow.com/questions/1534147/select-all-columns-from-all-tables-in-sql-server-2008

http://stackoverflow.com/questions/7106108/display-all-data-of-all-tables
 
Share this answer
 
v2
Comments
sankmahesh 16-Oct-13 5:19am    
Thankyou Thomas,

i already work that...

but i dont know what are the tables available the database..

when i select any database from webconfig then automatically load all table. i mainly need the table name.

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