我有一个GridView。如果我将其复制并粘贴到SQL Server Management Studio中,我的代码中的SelectCommand将起作用。它执行得很好。
如果我运行该页面并单击任何行的编辑,则会收到错误:
“关键字'IS'附近的语法不正确。”
我试图了解使用SQL Server Profiler的情况。这是SelectCommand的样子以及SQL正在接收的内容......
来自supplies.ascx的SelectCommand
SELECT some stuff FROM here WHERE (this IS NULL) and (that=1) ORDER BY this DESC
SQL Server Profiler报告
SELECT some stuff FROM here (this IS NULL) and (that=1) ORDER BY this DESC
我没有在这里放任何代码,因为我不确定什么是相关的,并且不想用不必要的代码行加载帖子。请告诉我您希望看到的帮助。
请求下面的代码。我没有放入GridView中的所有内容......它非常大。如果需要,我可以更新。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="fldSupReqID"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." AllowSorting="True"
CellPadding="4" ForeColor="#333333" Font-Size="10px">
<RowStyle BackColor="#EFF3FB" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
DeleteCommand="DELETE FROM [tblSupplyRequests] WHERE [fldSupReqID] = @fldSupReqID"
InsertCommand="INSERT INTO [tblSupplyRequests] ([fldManufacturerID], [fldItemID], [fldFeeTypeID], [fldRequestDate], [fldStamp], [fldAddedByUser], [fldBID]) VALUES (@fldManufacturerID, @fldItemID, @fldFeeTypeID, @fldRequestDate, @fldStamp, @fldAddedByUser, @fldBID)"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>" SelectCommand="SELECT tblSupplyRequests.fldSupReqID, tblSupplyRequests.fldOrderToShipDate, tblSupplyRequests.fldBID AS BID, tblMerchantIDs.fldMerchantID AS MerchantID, salescontactinfo.sname_of_business AS [Merchant Name], salescontactinfo.scontactname1 AS Contact, salescontactinfo.scontactn1phone1 AS Phone, tblSupplyRequests.fldRequestDate, tblSupplyRequests.fldAddedByUser AS RequestedBy, INVtblManufacturers.fldManufacturerName AS [Term Manuf], INVtblInventoryItems_1.fldItemName AS [Term Model], INVtblInventoryTypes.fldInventoryTypename AS [Item Type], tblSupplyRequests.fldNumItemsRequested AS [Num Items], tblSupplyRequests.fldPaperItemID, tblSupplyRequests.fldPerItemCost, INVtblInventoryItems.fldMiscDesc, tblSupplyRequests.fldPersonCalling, tblSupplyRequests.fldTitlePersonCalling, tblSupplyRequests.fldNotes, salescontactinfo.sstate, tblSupplyRequests.fldManufacturerID, tblSupplyRequests.fldItemID, tblSupplyRequests.fldStamp, tblSupplyRequests.fldOrderToShipDate AS Expr1, tblSupplyRequests.fldOrderToShipBy FROM INVtblInventoryItems INNER JOIN tblSupplyRequests INNER JOIN salescontactinfo ON tblSupplyRequests.fldBID = salescontactinfo.sbusinessid LEFT OUTER JOIN tblMerchantIDs ON salescontactinfo.sbusinessid = tblMerchantIDs.fldBID LEFT OUTER JOIN INVtblManufacturers ON tblSupplyRequests.fldManufacturerID = INVtblManufacturers.fldManufacturerID ON INVtblInventoryItems.fldItemID = tblSupplyRequests.fldPaperItemID LEFT OUTER JOIN INVtblInventoryTypes ON tblSupplyRequests.fldInventoryTypeID = INVtblInventoryTypes.fldInventoryTypeID LEFT OUTER JOIN INVtblInventoryItems AS INVtblInventoryItems_1 ON tblSupplyRequests.fldItemID = INVtblInventoryItems_1.fldItemID WHERE (tblSupplyRequests.fldOrderToShipDate IS NULL) AND (tblMerchantIDs.fldMIDStatusID=1) ORDER BY tblSupplyRequests.fldRequestDate DESC"
UpdateCommand="UPDATE tblSupplyRequests SET fldOrderToShipDate=@fldOrderToShipDate, fldNotes = @fldNotes, fldTitlePersonCalling = @fldTitlePersonCalling, fldPersonCalling = @fldPersonCalling, fldRequestDate = @fldRequestDate WHERE (fldSupReqID = @fldSupReqID)">
<DeleteParameters>
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="fldManufacturerID" Type="Int32" />
<asp:Parameter Name="fldItemID" Type="Int32" />
<asp:Parameter Name="fldFeeTypeID" Type="Int32" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldStamp" Type="DateTime" />
<asp:Parameter Name="fldAddedByUser" Type="String" />
<asp:Parameter Name="fldBID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="fldOrderToShipDate" Type="DateTime" />
<asp:Parameter Name="fldNotes" Type="String" />
<asp:Parameter Name="fldTitlePersonCalling" Type="String" />
<asp:Parameter Name="fldPersonCalling" Type="String" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
这就是SQL Server Profiler捕获的内容......
SELECT tblSupplyRequests.fldSupReqID, tblSupplyRequests.fldOrderToShipDate, tblSupplyRequests.fldBID AS BID, tblMerchantIDs.fldMerchantID AS MerchantID, salescontactinfo.sname_of_business AS [Merchant Name], salescontactinfo.scontactname1 AS Contact, salescontactinfo.scontactn1phone1 AS Phone, tblSupplyRequests.fldRequestDate, tblSupplyRequests.fldAddedByUser AS RequestedBy, INVtblManufacturers.fldManufacturerName AS [Term Manuf], INVtblInventoryItems_1.fldItemName AS [Term Model], INVtblInventoryTypes.fldInventoryTypename AS [Item Type], tblSupplyRequests.fldNumItemsRequested AS [Num Items], tblSupplyRequests.fldPaperItemID, tblSupplyRequests.fldPerItemCost, INVtblInventoryItems.fldMiscDesc, tblSupplyRequests.fldPersonCalling, tblSupplyRequests.fldTitlePersonCalling, tblSupplyRequests.fldNotes, salescontactinfo.sstate, tblSupplyRequests.fldManufacturerID, tblSupplyRequests.fldItemID, tblSupplyRequests.fldStamp, tblSupplyRequests.fldOrderToShipDate AS Expr1, tblSupplyRequests.fldOrderToShipBy FROM INVtblInventoryItems INNER JOIN tblSupplyRequests INNER JOIN salescontactinfo ON tblSupplyRequests.fldBID = salescontactinfo.sbusinessid LEFT OUTER JOIN tblMerchantIDs ON salescontactinfo.sbusinessid = tblMerchantIDs.fldBID LEFT OUTER JOIN INVtblManufacturers ON tblSupplyRequests.fldManufacturerID = INVtblManufacturers.fldManufacturerID ON INVtblInventoryItems.fldItemID = tblSupplyRequests.fldPaperItemID LEFT OUTER JOIN INVtblInventoryTypes ON tblSupplyRequests.fldInventoryTypeID = INVtblInventoryTypes.fldInventoryTypeID LEFT OUTER JOIN INVtblInventoryItems AS INVtblInventoryItems_1 ON tblSupplyRequests.fldItemID = INVtblInventoryItems_1.fldItemID (tblSupplyRequests.fldOrderToShipDate IS NULL) AND (tblMerchantIDs.fldMIDStatusID=1) ORDER BY tblSupplyRequests.fldRequestDate DESC
答案 0 :(得分:0)
我不想这么说,但可能只是因为ASP.NET在一行之前的所有嵌套INNER JOIN
都错误地解析了查询。我想知道格式化SQL是否会有所帮助? neatly formatting your SQL statements在线有一个非常酷的工具。
以下是SQLDataSource
的格式化版本:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
DeleteCommand=" DELETE FROM [tblSupplyRequests]
WHERE [fldSupReqID] = @fldSupReqID"
InsertCommand=" INSERT INTO [tblSupplyRequests] ([fldManufacturerID],[fldItemID],[fldFeeTypeID],[fldRequestDate],[fldStamp],[fldAddedByUser],[fldBID])
VALUES (@fldManufacturerID,@fldItemID,@fldFeeTypeID,@fldRequestDate,@fldStamp,@fldAddedByUser,@fldBID)"
ProviderName="<%$ ConnectionStrings:myConnectionString.ProviderName %>"
SelectCommand=" SELECT tblsupplyrequests.fldsupreqid,
tblsupplyrequests.fldordertoshipdate,
tblsupplyrequests.fldbid AS bid,
tblmerchantids.fldmerchantid AS merchantid,
salescontactinfo.sname_of_business AS [Merchant Name],
salescontactinfo.scontactname1 AS contact,
salescontactinfo.scontactn1phone1 AS phone,
tblsupplyrequests.fldrequestdate,
tblsupplyrequests.fldaddedbyuser AS requestedby,
invtblmanufacturers.fldmanufacturername AS [Term Manuf],
invtblinventoryitems_1.flditemname AS [Term Model],
invtblinventorytypes.fldinventorytypename AS [Item Type],
tblsupplyrequests.fldnumitemsrequested AS [Num Items],
tblsupplyrequests.fldpaperitemid,
tblsupplyrequests.fldperitemcost,
invtblinventoryitems.fldmiscdesc,
tblsupplyrequests.fldpersoncalling,
tblsupplyrequests.fldtitlepersoncalling,
tblsupplyrequests.fldnotes,
salescontactinfo.sstate,
tblsupplyrequests.fldmanufacturerid,
tblsupplyrequests.flditemid,
tblsupplyrequests.fldstamp,
tblsupplyrequests.fldordertoshipdate AS expr1,
tblsupplyrequests.fldordertoshipby
FROM invtblinventoryitems
INNER JOIN tblsupplyrequests
INNER JOIN salescontactinfo
ON tblsupplyrequests.fldbid = salescontactinfo.sbusinessid
LEFT OUTER JOIN tblmerchantids
ON salescontactinfo.sbusinessid = tblmerchantids.fldbid
LEFT OUTER JOIN invtblmanufacturers
ON tblsupplyrequests.fldmanufacturerid = invtblmanufacturers.fldmanufacturerid
ON invtblinventoryitems.flditemid = tblsupplyrequests.fldpaperitemid
LEFT OUTER JOIN invtblinventorytypes
ON tblsupplyrequests.fldinventorytypeid = invtblinventorytypes.fldinventorytypeid
LEFT OUTER JOIN invtblinventoryitems AS invtblinventoryitems_1
ON tblsupplyrequests.flditemid = invtblinventoryitems_1.flditemid
WHERE ( tblsupplyrequests.fldordertoshipdate IS NULL )
AND ( tblmerchantids.fldmidstatusid = 1 )
ORDER BY tblsupplyrequests.fldrequestdate DESC"
UpdateCommand=" UPDATE tblsupplyrequests
SET fldordertoshipdate = @fldOrderToShipDate,
fldnotes = @fldNotes,
fldtitlepersoncalling = @fldTitlePersonCalling,
fldpersoncalling = @fldPersonCalling,
fldrequestdate = @fldRequestDate
WHERE ( fldsupreqid = @fldSupReqID )" >
<DeleteParameters>
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="fldManufacturerID" Type="Int32" />
<asp:Parameter Name="fldItemID" Type="Int32" />
<asp:Parameter Name="fldFeeTypeID" Type="Int32" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldStamp" Type="DateTime" />
<asp:Parameter Name="fldAddedByUser" Type="String" />
<asp:Parameter Name="fldBID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="fldOrderToShipDate" Type="DateTime" />
<asp:Parameter Name="fldNotes" Type="String" />
<asp:Parameter Name="fldTitlePersonCalling" Type="String" />
<asp:Parameter Name="fldPersonCalling" Type="String" />
<asp:Parameter Name="fldRequestDate" Type="DateTime" />
<asp:Parameter Name="fldSupReqID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
注意:如果SQLDataSource中的查询变得复杂,您可能需要考虑将此逻辑移动到类/数据访问层以便将来维护。话虽如此,我明白,有时你会被时间紧迫的东西=)祝你好运!