SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnFinalProject"].ToString());
SqlCommand cmd = new SqlCommand(@"SELECT c.partID, p.name, p.categoryID, p.price, p.image, p.subCategoryID,
(CASE WHEN categoryID = 1 THEN 'Y' ELSE 'N' END) AS casesYN,
(CASE WHEN categoryID = 3 THEN 'Y' ELSE 'N' END) AS OSYN,
(CASE WHEN categoryID = 7 THEN 'Y' ELSE 'N' END) AS HDDYN,
(CASE WHEN subCategoryID = 1 THEN 'Y' ELSE 'N' END) AS powerYN,
(CASE WHEN subCategoryID = 2 THEN 'Y' ELSE 'N' END) AS processorYN,
(CASE WHEN subCategoryID = 3 THEN 'Y' ELSE 'N' END) AS moboYN,
(CASE WHEN subCategoryID = 4 THEN 'Y' ELSE 'N' END) AS memoryYN,
(CASE WHEN subCategoryID = 5 THEN 'Y' ELSE 'N' END) AS graphicsYN,
(CASE WHEN subCategoryID = 6 THEN 'Y' ELSE 'N' END) AS opticalYN,
(CASE WHEN subCategoryID = 7 THEN 'Y' ELSE 'N' END) AS soundYN
FROM configuration c JOIN parts p ON p.partID = c.partID
WHERE c.customID = @ID", conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string[] cases = { dr["partID"].ToString() };
}
如何仅将“casesYN”值设置为 Y 的“partID”插入到 case 数组中,因为现在它将在 sql 查询中插入每个“partID”。