我不是一個非常有經驗的程序員,所以請耐心等待!我必須根據另一個表格(ProdDesigns)的數據從表格(Chemie)中提取數據。顯而易見的答案是使用子查詢。事情是這樣的:
C中的SQL子查詢#
SELECT chemie.rmcode,
chemie.sio2,
chemie.al2o3,
chemie.fe2o3,
chemie.feo,
chemie.tio2,
chemie.cao,
chemie.mgo,
chemie.na2o,
chemie.k2o,
chemie.cr2o3,
chemie.p2o5,
chemie.sic,
chemie.c,
chemie.mno,
chemie.zro2,
chemie.b2o3
FROM chemie
INNER JOIN proddesigns
ON chemie.rmcode = proddesigns.rmcode
WHERE chemie.rmcode = (SELECT proddesigns.rmcode
FROM proddesigns
WHERE proddesigns.batchno = 1234)
的問題是,從表ProdDesigns數據的子集將永遠是多條記錄,所以我得到的錯誤。所以我「最多一個記錄可以通過該子查詢將返回」想着使用臨時表並嘗試以下內容:
conn.Open();
OleDbCommand cmdRM = null;
cmdRM = conn.CreateCommand();
cmdRM.CommandText = (@"SELECT * INTO ##tempTest FROM ProdDesigns WHERE batchNo = 1234");
cmdRM.ExecuteNonQuery();
dataAdapter2 = new OleDbDataAdapter(@"SELECT Chemie.RMCode, Chemie.SiO2, Chemie.Al2O3, Chemie.Fe2O3, Chemie.FeO, Chemie.TiO2, Chemie.CaO, Chemie.MgO, Chemie.Na2O, Chemie.K2O, Chemie.Cr2O3, Chemie.P2O5, Chemie.SiC, Chemie.C, Chemie.MnO, Chemie.ZrO2, Chemie.B2O3
FROM Chemie INNER JOIN ##tempTest ON Chemie.RMCode = ##tempTest.rmCode
WHERE ((Chemie.RMCode)= ##tempTest.rmCode)", conn);
dataAdapter2.Fill(dataS2, "Chemie");
dtChem = dataS2.Tables["Chemie"];
任何反饋將不勝感激!
良好的格式始終是你的朋友。 –
這是我的第一篇文章,所以我對可憐的格式化,縮進等等道歉。 – BabyDoll
請不要道歉。我們都以這種方式通過..你可以閱讀[常問問題]和[問]作爲開始';) –