Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

How can I bring back multiplet tables in a dataset?

Hi, I'm using asp.net 3.5, C#
How can I modified my current method to return multiple tables in a same dataset?  Thank you

    public DataSet SelectFromATable(string tableName)
    {
        string query = "select * from @tableName";
        SqlCommand cmd = new SqlCommand(query);
        cmd.Parameters.Add(@tableName, SqlDbType.NVarChar);
        cmd.Parameters["@tableName"].Value = tableName;
        return FillDataSet(cmd, tableName);
    }

   private DataSet FillDataSet(SqlCommand cmd, string tableName)
    {
        SqlConnection con = new SqlConnection(connectionString);
        cmd.Connection = con;
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        try
        {
            con.Open();
            adapter.Fill(ds, tableName);

        }
        finally
        {
            con.Close();
            con.Dispose();
        }
        return ds;
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca
lapucca

ASKER

smart!  Thank you.