简体   繁体   English

不允许从数据类型sql_variant隐式转换为varbinary(max)。 使用CONVERT函数运行此查询。 ASP.NET SQL数据源

[英]Implicit conversion from data type sql_variant to varbinary(max) is not allowed. Use the CONVERT function to run this query. ASP.NET SQL DataSource

Although, there are a lot of questions with this title, but mine is different. 虽然这个标题有很多疑问,但是我的却有所不同。

I am using a ASP.NET ListView bound to a sql datasource control & as such have not added any conversions. 我正在使用绑定到sql数据源控件的ASP.NET ListView,因此未添加任何转换。 Also I am sending DBNull value in ListView's Inserting Event. 我也在ListView的插入事件中发送DBNull值。

The DataSource Code: 数据源代码:

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Main %>"  InsertCommand="pInsert" InsertCommandType="StoredProcedure" 
    SelectCommand="pGet" SelectCommandType="StoredProcedure"   >
            <DeleteParameters>
                <asp:Parameter Name="Code" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:SessionParameter Name="SubscriptionCode" SessionField="EntryCode" Type="Int32" DefaultValue="-1" />
                <asp:Parameter Name="Attachment" Type="Object" />

            </InsertParameters>
            <SelectParameters>                
                <asp:SessionParameter Name="SubscriptionCode" SessionField="EntryCode" Type="Int32" DefaultValue="-1" />
                <asp:Parameter DefaultValue="false" Name="ForEdit" Type="Boolean" />
            </SelectParameters>           
        </asp:SqlDataSource>

The Code Behind : 背后的代码:

protected void lv_ItemInserting(object sender, ListViewInsertEventArgs e)
        {           
            e.Values["Attachment"] = DBNull.Value;
        }   

I have also tried removing the Type="Object" property as specified here 我也尝试过删除此处指定的Type="Object"属性

Remove the Type="Object" property from this line <asp:Parameter Name="Attachment" Type="Object" /> and try this in code behind : 从此行<asp:Parameter Name="Attachment" Type="Object" />删除Type="Object"属性,并在后面的代码中尝试以下操作:

protected void lv_ItemInserting(object sender, ListViewInsertEventArgs e)
{
   e.Values["Attachment"] = System.Data.SqlTypes.SqlBinary.Null;
}

Here is another solution. 这是另一种解决方案。 Just try the code below. 只需尝试下面的代码。

The DataSource Code : 数据源代码:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Main %>"  InsertCommand="pInsert" InsertCommandType="StoredProcedure" 
SelectCommand="pGet" SelectCommandType="StoredProcedure"   >
    <DeleteParameters>
        <asp:Parameter Name="Code" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:SessionParameter Name="SubscriptionCode" SessionField="EntryCode" Type="Int32" DefaultValue="-1" />
        <asp:Parameter Name="Attachment" />

    </InsertParameters>
    <SelectParameters>                
        <asp:SessionParameter Name="SubscriptionCode" SessionField="EntryCode" Type="Int32" DefaultValue="-1" />
        <asp:Parameter DefaultValue="false" Name="ForEdit" Type="Boolean" />
    </SelectParameters>           
</asp:SqlDataSource>

The Code Behind : 背后的代码:

protected void lv_ItemInserting(object sender, ListViewInsertEventArgs e)
{
   e.Values["Attachment"] = -1;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - Error : Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query 不允许从数据类型nvarchar到二进制的隐式转换。 使用CONVERT函数运行此查询。 - Implicit conversion from data type nvarchar to binary is not allowed. Use the CONVERT function to run this query. System.Data.SqlClient.SqlException:不允许从数据类型sql_variant到uniqueidentifier的隐式转换。 - System.Data.SqlClient.SqlException: Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. 不允许从数据类型 sql_variant 隐式转换为 varchar - Implicit conversion from data type sql_variant to varchar is not allowed 不允许从数据类型datetime到int的隐式转换错误。 使用CONVERT函数运行此查询 - Error of Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query Dapper:不允许从数据类型 datetime 到 int 的隐式转换。 使用 CONVERT function 运行此查询 - Dapper: Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query 回滚迁移错误不允许从数据类型datetime到int的隐式转换。 使用CONVERT函数运行此查询 - Roll Back Migration Error Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query 如何处理异常不允许从数据类型varchar隐式转换为varbinary(max)。 在将数据添加到数据库时 - how to handle the exception Implicit conversion from data type varchar to varbinary(max) is not allowed. while adding the data to database 不允许从数据类型nvarchar隐式转换为varbinary(max) - Implicit conversion from data type nvarchar to varbinary(max) is not allowed 无法在错误的varbinary(max)中插入空值:不允许从数据类型nvarchar隐式转换为varbinary(max) - Cannot insert null value in varbinary(max) with error : implicit conversion from data type nvarchar to varbinary(max) is not allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM