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(@tableN ame, SqlDbType.NVarChar);
cmd.Parameters["@tableName "].Value = tableName;
return FillDataSet(cmd, tableName);
}
private DataSet FillDataSet(SqlCommand cmd, string tableName)
{
SqlConnection con = new SqlConnection(connectionSt ring);
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;
}
}
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(@tableN
cmd.Parameters["@tableName
return FillDataSet(cmd, tableName);
}
private DataSet FillDataSet(SqlCommand cmd, string tableName)
{
SqlConnection con = new SqlConnection(connectionSt
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER