Select from multiple tables in one call

前端 未结 7 1161
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 13:01

In my code I have a page that includes information from 3 different tables. To show this information I make 3 SQL select calls and unite them in one list to pass as Model to my

7条回答
  •  忘掉有多难
    2021-02-13 13:42

    DO NOT USE UNION. DataAdapter is weapon of choise.

    var commandText = "SELECT * FROM Table1; SELECT * FROM Table2;";
    var ds = new DataSet();
    using (var da = new SqlDataAdapter(commandText, "your cn"))
    {
        da.Fill(ds);
    }
    

    Using:

    ds.Tables["Table1"]...
    ds.Tables["Table2"]...
    

提交回复
热议问题