One sql query to return as multiple tables in dataset

I was wondering if I could use one query in SQL Server 2005 to return as a dataset in C #, 2005 to different tables.

DataSet ds = new DataSet();
ds = new BusinessLogic.BizLogic().getData(int repID);
for(ds != null)
    txtDate.Text = ds.Tables[2].Rows[0]["Date"].ToString();


Looking to figure out how to write a storage routine to have multiple tables. A simple example would be appreciated. Thank!


source to share

2 answers

You absolutely can, although you can consider the overall purpose and implications of considering this project.

Your stored procedure just simply has multiple options ala ..

select xxx, yyy from table1
select zzz, nnn from table2


Along these lines.



Yes it is easy, you can do it via proc or via inline sql, but as in the above poster, think about the implications.

 using (var sqlConn = new SqlConnection("Server=localhost;Database=Test;Integrated Security=SSPI"))
                string sql = "Select * From table1; Select * From table2;";
                using (var sqlCmd = new SqlCommand(sql, sqlConn))
                    var da = new SqlDataAdapter(sqlCmd);
                    var ds = new DataSet();
                    Console.WriteLine(ds.Tables.Count); // Will show 2 !






All Articles