当我尝试执行查询时遇到问题。我收到此错误:
找不到列“m”或用户定义的函数或聚合“m.gender”,或者名称不明确
代码:
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader() /* Problem is here */
Return myReader
当我直接在 SQL Server 中执行时,查询运行良好。问题是当它在我的应用程序中的按钮单击事件上执行时。(VB.NET)
请检查我的整个查询
SELECT pt.color as Color, m.model As Model, m.gender AS Gender,
SUM(CASE
WHEN MONTH(o.data_ins) = 1 THEN 1
ELSE 0
END) Jan,
SUM(CASE
WHEN MONTH(o.data_ins) = 2 THEN 1
ELSE 0
END) Feb,
SUM(CASE
WHEN MONTH(o.data_ins) = 3 THEN 1
ELSE 0
END) Mar,
SUM(CASE
WHEN MONTH(o.data_ins) = 4 THEN 1
ELSE 0
END) Apr,
SUM(CASE
WHEN MONTH(o.data_ins) = 5 THEN 1
ELSE 0
END) May,
SUM(CASE
WHEN MONTH(o.data_ins) = 6 THEN 1
ELSE 0
END) Jun,
SUM(CASE
WHEN MONTH(o.data_ins) = 7 THEN 1
ELSE 0
END) Jul,
SUM(CASE
WHEN MONTH(o.data_ins) = 8 THEN 1
ELSE 0
END) Ago,
SUM(CASE
WHEN MONTH(o.data_ins) = 9 THEN 1
ELSE 0
END) Sep,
SUM(CASE
WHEN MONTH(o.data_ins) = 10 THEN 1
ELSE 0
END) Oct,
SUM(CASE
WHEN MONTH(o.data_ins) = 11 THEN 1
ELSE 0
END) Nov,
SUM(CASE
WHEN MONTH(o.data_ins) = 12 THEN 1
ELSE 0
END) Dec
FROM models m
INNER JOIN product_type pt
ON m.model_id = pt.model_id
INNER JOIN product_orders po
ON pt.producttype_id = po.producttype_id
INNER JOIN orders o
ON po.order_id = o.order_id
WHERE YEAR(o.date_ins) = 2013 and pt.available = 1 and p.status = 'shipped'
GROUP BY pt.color,
m.model,
m.gender
ORDER BY pt.color,
m.model,
m.gender
>
Public Shared Function ExecutaReader(ByVal strSQL)
Dim strConn As String
strConn = ConfigurationSettings.AppSettings("strConn")
Dim myConnection As New SqlConnection(strConn)
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader()
Return myReader
End Function