[英]Stored procedure expects parameter that was not supplied
I have a SqlDataSource
connected to a GridView and I am trying to get the edit working correctly, but with everything I try I still get that parameters are not supplied. 我有一个连接到GridView的
SqlDataSource
,我试图使编辑正常工作,但是我尝试使用的所有方法仍然得到未提供参数的信息。
I have tried naming the parameters with and without the '@', it seems to make no difference. 我尝试使用和不使用'@'来命名参数,这似乎没有什么区别。 As you can see in the below image, the update parameters exist and even have values!
如下图所示,更新参数存在,甚至具有值!
Example image: 示例图片:
ASPX markup: ASPX标记:
<asp:GridView runat="server" ID="JobGV" DataSourceID="JobApprovalsDS"
AutoGenerateColumns="False" AutoGenerateEditButton="true"
OnRowCommand="JobGV_OnRowCommand" OnRowUpdating="JobGV_OnRowUpdating">
<Columns>
<asp:BoundField HeaderText="Function" DataField="FunDesc" ReadOnly="true"/>
<asp:BoundField HeaderText="Employee" DataField="EmpName" ReadOnly="true"/>
<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlEmps" SelectedValue='<%# Eval("appEmpID")%>' DataSourceID="EmpDS" DataTextField="EmpName" DataValueField="EmpID" />
<asp:Label runat="server" ID="data" Text='<%# Eval("appBusinessUnit") +";" + Eval("appFunctID") %>' Visible="False"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("EmpName") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate">
<SelectParameters>
<asp:Parameter Name="ShowAll" DefaultValue="1" />
<asp:Parameter Name="AllPhases" DefaultValue="1" />
<asp:ControlParameter Name="BusinessUnit" ControlID="ddlEditJob" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="@BusinessUnit" Type="String"/>
<asp:Parameter Name="@FunctID" Type="Int32"/>
<asp:Parameter Name="@EmpID" Type="Int32"/>
<asp:Parameter Name="@UpdateDate" Type="DateTime"/>
</UpdateParameters>
</asp:SqlDataSource>
C#: C#:
protected void JobGV_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Update"))
{
int empid = 0;
string[] data;
int index = int.Parse(e.CommandArgument.ToString());
GridViewRow row = JobGV.Rows[index];
DropDownList ddlemp = (DropDownList) row.FindControl("ddlEmps");
empid = int.Parse(ddlemp.SelectedValue);
Label lbl = (Label) row.FindControl("data");
data = lbl.Text.Split(';');
JobApprovalsDS.UpdateParameters["@BusinessUnit"].DefaultValue = data[0];
JobApprovalsDS.UpdateParameters["@FunctID"].DefaultValue = data[1];
JobApprovalsDS.UpdateParameters["@EmpID"].DefaultValue = empid.ToString();
//JobApprovalsDS.UpdateParameters.Add("BusinessUnit", data[0]);
//JobApprovalsDS.UpdateParameters.Add("FunctID", data[1]);
//JobApprovalsDS.UpdateParameters.Add("EmpID", empid.ToString());
}
}
protected void JobGV_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
JobApprovalsDS.Update();
}
Are you talking about the update process?? 您在谈论更新过程吗?
Well, in your SqlDataSource
, you're not specifying that the UpdateCommand
is talking to a stored procedure... you need to specify the UpdateCommandType
, too! 好吧,在您的
SqlDataSource
,您没有指定UpdateCommand
正在与存储过程进行通讯……您还需要指定UpdateCommandType
! (not just the SelectCommandType
) (而不仅仅是
SelectCommandType
)
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate"
UpdateCommandType="StoredProcedure" > **** this is missing from your code!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.