[英]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.