繁体   English   中英

单个sql查询作为数据集中的多个表返回

[英]A single sql query to return as multiple tables in a dataset

我想知道我是否可以在sql server 2005中使用单个查询作为c#,asp.net 2005中的数据集返回到不同的表中。

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

想弄清楚,如何编写存储过程以拥有多个表。一个简单的例子将不胜感激。 谢谢!

你绝对可以,尽管你可能想要考虑考虑这个设计的总体目标和影响。

在您的存储过程中,您只需要多个选择ala ..

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

沿着这些路线。

是的,它很容易,你可以通过proc或内联sql来做,但像上面的海报所说,考虑其含义。

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

                }

            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM