By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,258 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,258 IT Pros & Developers. It's quick & easy.

Parameterized Query expects parameter @Company, which was not supplied.

P: 1
I am trying to pass a parameter to dynamically populate drop down list. I am not able to pass the parameter from my .aspx file. Here is the grid view and related ObjectDataSource. In srcLocation, the Company paramter being passed is blank or null, if I put default value (hardcoding what is expected), the page display fine when I click on edit button. But with no default value it gives above error.

<asp:GridView
id="grdCAPAs"
DataSourceID="srcCAPAs"
DataKeyNames="CAPA_Number"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
AutoGenerateColumns="false"
CssClass="products"
GridLines="none"
Runat="server" >
<Columns>
<asp:BoundField
DataField="CAPA_Number"
ReadOnly="true"
HeaderText="CAPA Number" />
<asp:TemplateField HeaderText="Company" >
<ItemTemplate>
<%#Eval("Company", "{0}")%>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList
ID = "ddlCompany"
DataSourceID = "srcCompany"
DataTextField="C9_Company"
DataValueField = "C9_Company"
SelectedValue = '<%# Bind("Company", "{0}") %>'
Runat = "server"
Autopostback = "true" />

</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Location" >
<ItemTemplate>
<%#Eval("Location", "{0}")%>
</ItemTemplate>

<EditItemTemplate>
<asp:DropDownList
ID = "ddlLocation"
DataSourceID = "srcLocation"
DataTextField="C9_Location"
DataValueField = "C9_Location"
SelectedValue = '<%# Bind("Location", "{0}") %>'
Runat = "server" />

</EditItemTemplate>
</asp:TemplateField>

<asp:BoundField
DataField="Area"
HeaderText="Area" />


<asp:ObjectDataSource
id="srcCAPAs"
TypeName="CAPAs.BLL.MaintainCAPA"
SelectMethod="SelectAll"
UpdateMethod="Update"
InsertMethod="Insert"
DeleteMethod="Delete"
Runat="server" />

<asp:ObjectDataSource
id = "srcCompany"
TypeName="CAPAs.BLL.MaintainCAPA"
SelectMethod="SelectCompany"
Runat = "server" />

<asp:ObjectDataSource
id = "srcLocation"
TypeName="CAPAs.BLL.MaintainCAPA"
SelectMethod="SelectLocation"

Runat = "server" >
<SelectParameters>
<asp:ControlParameter ControlID="grdCAPAs" Name = "Company" PropertyName ="SelectedValue" />
</SelectParameters>
</asp:ObjectDataSource>


Public Shared Function SelectLocation(ByVal Company As String)
Dim daLayer As DAL1 = New DAL1()
Return daLayer.SelectAllLocation(Company)
End Function


Public Function SelectAllLocation(ByVal Company As String) As SqlDataReader
'Create Connection
Dim con As New SqlConnection(_connectionString)

'Create Command
Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = con
cmd.CommandText = "SELECT DISTINCT C9_LOCATION FROM CAPA_LOCATION WHERE C9_COMPANY = @Company"
'Add parameters
cmd.Parameters.AddWithValue("@Company", Company)

'Return DataReader
con.Open()
Return cmd.ExecuteReader(CommandBehavior.CloseConnection)
End Function

Let me know what you think
May 3 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.