當我做查詢創建一個新表與其他表
SELECT a.ID,
a.Employee,
b.Name,
b.[Open Date]
FROM tblEmployees a,
Stores b
它工作得很好,但是當我做查詢
SELECT a.ID,
a.Employee,
b.Name,
b.[Open Date],
c.Task
FROM tblEmployees a,
Stores b,
tblTasks c
它不工作。
它不斷sda.Fill(dt)
給了一個錯誤:
的System.OutOfMemoryException: 'System.OutOfMemoryException的'
private DataTable GetData()
{
string connString = @"Data Source=aa.database.windows.net;Initial Catalog=aa;Persist Security Info=True;User ID=aa;Password=aa";
string query = "SELECT a.ID, a.Employee, b.Name, b.[Open Date], c.Task FROM tblEmployees a, Stores b, tblTasks c";
using (SqlConnection con = new SqlConnection(connString))
{
using (SqlCommand comm = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
comm.Connection = con;
sda.SelectCommand = comm;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
查詢返回多少條記錄? – hardkoded
[system.outofmemoryexception填充DataAdapter時可能有的重複?](https://stackoverflow.com/questions/5092510/system-outofmemoryexception-when-filling-dataadapter) – sab669
您使用舊式連接語法:'FROM tblEmployees,商店,tblTasks'將返回所有這些表的笛卡爾乘積('CROSS JOIN'),這可能會很大 - 而且根本不是你想要的。閱讀'INNER JOIN'。如果您希望以某種方式在一個查詢中查找所有表,您需要一個'UNION ALL'(但您會得到一組奇怪的列),或者只是將三個單獨的查詢分成三個單獨的表。 –