#22004/10/6 3:02:09
晚上,我仔细做了,看了些参考书,觉得用一句SQL难以表达,所以分二组,
一组为得到仓库列表
二组为最后结果SQL语句完成。
用DataSet来存储仓库信息及查询结果
DataSet dsUse;
dsUse = new DataSet
dsUse.Tables.Add("Storeroom") //仓库表
dsUse.Tables.Add("StoerSearch") //查询表
查询仓库很方便
SELECT * FROM Storeroom ORDER BY StoreroomID
然后就Fill到dsUse.Table["Storeroom"]表去了
写查询句较复杂
string sql = "SELECT Code, BrandAndName";
for (int i = 0; i < dsUse.Tables["Storeroom"].Rows.Count; i++)
{
sql += ",";
sql += "(SELECT Amount FROM StoreProduct"
+ " WHERE StoreProduct.ProductID = Product.ProductID"
+ " AND StoreroomID = " + dsUse.Tables["Storeroom"].Rows[i]["StoreroomID"].ToString() + ")";
sql += " AS [" + dsUse.Tables["Storeroom"].Rows[i]["Name"].ToString() + "]";
}
sql += " FROM Product";
后面就不多说了,结果很成功。当然明天我还要完成一些更漂亮的后缀活。
非常大鱼