C# 更新Int32列get";输入字符串的格式不正确";

C# 更新Int32列get";输入字符串的格式不正确";,c#,asp.net,C#,Asp.net,我有一个更新db表的webform,提交表单后出现错误“输入字符串格式不正确” nodeDetails.cs protected void SqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e) { DropDownList ddl = (DropDownList)(DetailsView1.Rows[0].FindControl("DropDownList4")); DataRowView d

我有一个更新db表的webform,提交表单后出现错误“输入字符串格式不正确”

nodeDetails.cs

protected void SqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
    DropDownList ddl = (DropDownList)(DetailsView1.Rows[0].FindControl("DropDownList4"));
    DataRowView dr = (DataRowView)DetailsView1.DataItem;

    e.Command.Parameters["@parent_id"].Value = ddl.SelectedValue;

}
nodeDetails.aspx中的一些代码

UpdateCommand="UPDATE [node] SET [title] = @title, [parent_id] = @parent_id, [oid] = @oid, [display] = @display, [linkById] = @linkById, [showContent] = @showContent, [customLinks] = @customLinks, [contentType] = @contentType WHERE [id] = @id"

    <UpdateParameters>
        <asp:Parameter Name="title" Type="String" />
        <asp:Parameter Name="parent_id" Type="Int32" />
        <asp:Parameter Name="oid" Type="Int32" />
        <asp:Parameter Name="display" Type="Byte" />
        <asp:Parameter Name="linkById" Type="Byte" />
        <asp:Parameter Name="showContent" Type="Byte" />
        <asp:Parameter Name="customLinks" Type="String" />
        <asp:Parameter Name="contentType" Type="String" />
        <asp:Parameter Name="id" Type="Int32" />
    </UpdateParameters>
UpdateCommand=“更新[node]设置[title]=@title,[parent\u id]=@parent\u id,[oid]=@oid,[display]=@display,[linkById]=@linkById,[showContent]=@showContent,[customLinks]=@customLinks,[contentType]=@contentType其中[id]=@id]=@id”
错误将由e.Command.Parameters[“@parent_id”]引起。Value=ddl.SelectedValue


有人知道问题出在哪里吗?

在设置参数之前,您需要确保ddl.SelectedValue返回正确的整数值

DropDownList ddl = (DropDownList)(DetailsView1.Rows[0].FindControl("DropDownList4"));

int val;
if(int.TryParse(ddl.SelectedValue, out val)
{
   e.Command.Parameters["@parent_id"].Value = val;
}

绑定
DropDownList4
时,将整型字段设为其值成员。

数据格式不正确?