Reputation: 1679
I get this error when clicking on any of the letter buttons in my repeater. The sql statement I have works in sql server, but on my page it just errors out. The only thing that is different is that in sql server I change '@CompanyID' to an actual ID and '{0}' to 'a' so the query will run.
All the posts I have found online with this problem say something about this-->{0}, but I don't see anywhere that I might be trying to pass more than one argument or have this wrong.
<asp:repeater id="rptLetters" runat="server" datasourceid="dsLetters">
<headertemplate>
|
</headertemplate>
<itemtemplate>
<asp:linkbutton id="btnLetter" runat="server" onclick="btnLetter_Click"
text='<%#Eval("Letter")%>' />
</itemtemplate>
<separatortemplate>
|
</separatortemplate>
</asp:repeater>
Protected Sub btnLetter_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim btnLetter As LinkButton = TryCast(sender, LinkButton)
If btnLetter Is Nothing Then
Return
End If
'SELECT statement to filter Gridview
dsCategoryLookup.SelectCommand = [String].Format("SELECT
Category.CategoryID, Category.CategoryName, Product.ProductID,
Product.ProductName, Company.CompanyID
FROM Category
LEFT JOIN CategoryLink
ON Category.CategoryID = CategoryLink.CategoryID
LEFT JOIN Product ON Product.ProductID = CategoryLink.ProductID
LEFT JOIN CompanyLink ON CompanyLink.ProductID = Product.ProductID
LEFT JOIN Company ON Company.CompanyID = CompanyLink.CompanyID
WHERE (Category.CategoryName LIKE '{0}%')
AND Company.CompanyID = @CompanyID), btnLetter.Text")
'declare @CompanyID
dsCategoryLookup.SelectParameters.Clear()
Dim controlParam As ControlParameter = New ControlParameter
controlParam.ControlID = "ddlCompany"
controlParam.DefaultValue = "-1"
controlParam.Name = "CompanyID"
controlParam.PropertyName = "SelectedValue"
controlParam.Type = TypeCode.Decimal
dsCategoryLookup.SelectParameters.Add(controlParam)
End Sub
Upvotes: 0
Views: 2572
Reputation: 66
Is it just you have your quotation marks in the wrong place? The btnLetter.Text is inside your format string in your code:
dsCategoryLookup.SelectCommand = [String].Format("SELECT
Category.CategoryID, Category.CategoryName, Product.ProductID,
Product.ProductName, Company.CompanyID
FROM Category
LEFT JOIN CategoryLink
ON Category.CategoryID = CategoryLink.CategoryID
LEFT JOIN Product ON Product.ProductID = CategoryLink.ProductID
LEFT JOIN CompanyLink ON CompanyLink.ProductID = Product.ProductID
LEFT JOIN Company ON Company.CompanyID = CompanyLink.CompanyID
WHERE (Category.CategoryName LIKE '{0}%')
AND Company.CompanyID = @CompanyID)", btnLetter.Text)
Upvotes: 0