System.Data.SqlClient.EqlException: Operand type clash: varbinary(max) is incompatible with sql_variant
-
Friday, August 08, 2008 12:27 AM
I'm receiving the following error when I try to upload a binary file from Details View.
System.Data.SqlClient.SqlException: Operand type clash: varbinary(max) is incompatible with sql_variant
Here's my Details View Code:
<
asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" CellPadding="4" DataKeyNames="Detail_ID" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px" Width="125px"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" /> <RowStyle BackColor="#E3EAEB" /> <FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <Fields> <asp:BoundField DataField="Discipline_Name" HeaderText="Discipline_Name" SortExpression="Discipline_Name" /> <asp:BoundField DataField="Detail_Name" HeaderText="Detail_Name" SortExpression="Detail_Name" /> <asp:BoundField DataField="Detail_Descript" HeaderText="Detail_Descript" SortExpression="Detail_Descript" /> <asp:BoundField DataField="Detail_ID" HeaderText="Detail_ID" ReadOnly="True" SortExpression="Detail_ID" /> <asp:BoundField DataField="Sub_CategoryName" HeaderText="Sub_CategoryName" SortExpression="Sub_CategoryName" /> <asp:BoundField DataField="Detail_Comment" HeaderText="Detail_Comment" SortExpression="Detail_Comment" /> <asp:BoundField DataField="Detail_MOD_Date" HeaderText="Detail_MOD_Date" SortExpression="Detail_MOD_Date" /> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" /> <asp:TemplateField HeaderText="Detail DWG" SortExpression="Detail_dwg"> <EditItemTemplate> <input id="DWGUpload" type="file" /> </EditItemTemplate> <InsertItemTemplate> <input id="DWGUpload" type="file" /> </InsertItemTemplate> </asp:TemplateField> </Fields> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> <AlternatingRowStyle BackColor="White" /> </asp:DetailsView> <br /> <br /> <br /> <br /> <asp:ObjectDataSource ID="ObjectDataSource3" runat="server" InsertMethod="Load" SelectMethod="GetChanges" TypeName="DetailData"> <InsertParameters> <asp:Parameter Name="reader" Type="Object" /> <asp:Parameter Name="loadOption" Type="Object" /> <asp:Parameter Name="tables" Type="Object" /> </InsertParameters> </asp:ObjectDataSource> <asp:ObjectDataSource ID="DetailsObjDataSource" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData_Details" TypeName="DataSet_DetailsTableAdapters.DetailsSelectTableAdapter" DeleteMethod="Delete" UpdateMethod="Update"> <DeleteParameters> <asp:Parameter Name="Original_Discipline_Name" Type="String" /> <asp:Parameter Name="Original_Detail_Name" Type="String" /> <asp:Parameter Name="Original_Detail_ID" Type="String" /> <asp:Parameter Name="Original_Sub_CategoryName" Type="String" /> <asp:Parameter Name="Original_Detail_MOD_Date" Type="DateTime" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Discipline_Name" Type="String" /> <asp:Parameter Name="Detail_Name" Type="String" /> <asp:Parameter Name="Detail_Descript" Type="String" /> <asp:Parameter Name="Detail_dwg" Type="Object" /> <asp:Parameter Name="Sub_CategoryName" Type="String" /> <asp:Parameter Name="Detail_Comment" Type="String" /> <asp:Parameter Name="Detail_MOD_Date" Type="DateTime" /> <asp:Parameter Name="Original_Discipline_Name" Type="String" /> <asp:Parameter Name="Original_Detail_Name" Type="String" /> <asp:Parameter Name="Original_Detail_ID" Type="String" /> <asp:Parameter Name="Original_Sub_CategoryName" Type="String" /> <asp:Parameter Name="Original_Detail_MOD_Date" Type="DateTime" /> </UpdateParameters> <SelectParameters> <asp:Parameter Name="WhereCondition" Type="String" /> <asp:Parameter DefaultValue="" Name="OrderByExpression" Type="String" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="Discipline_Name" Type="String" /> <asp:Parameter Name="Detail_Name" Type="String" /> <asp:Parameter Name="Detail_Descript" Type="String" /> <asp:Parameter Name="Detail_dwg" Type="Object" /> <asp:Parameter Name="Detail_ID" Type="String" /> <asp:Parameter Name="Sub_CategoryName" Type="String" /> <asp:Parameter Name="Detail_Comment" Type="String" /> <asp:Parameter Name="Detail_MOD_Date" Type="DateTime" /> </InsertParameters> </asp:ObjectDataSource>
Here's my ItemInserting Event Handler:
protected
void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e){
//Reference the DWGUpload controls FileUpload DWGUpload = (FileUpload)DetailsView1.FindControl("DWGUpload"); if (DWGUpload.HasFile){
//Make sure that a DWG has been uploaded if (string.Compare(System.IO.Path.GetExtension(DWGUpload.FileName), ".dwg", true) != 0){
Console.WriteLine("Only DWG files can be uploaded.");}
}
else{
//No picture uploaded! Console.WriteLine("You must provide a dwg for the new detail.");}
//Set the value of the picture parametere.Values[
"DetailDWG"] = DWGUpload.FileBytes;}
All Replies
-
Friday, August 08, 2008 1:06 PM
change this:<asp:Parameter Name="Detail_dwg" Type="Object" />
to this:<asp:Parameter Name="Detail_dwg" />
and see if that does it for you.
-
Friday, August 08, 2008 3:36 PM
removing the type from the parameter didn't work.
If I wanted to convert the file to binary first before saving it to the database, how can I do this using the details view? Should I create another aspx page that will handle the conversion?
-
Friday, August 08, 2008 3:55 PMWhen you say "didn't work" do you mean you're still getting the same error message or is it a different message?
-
Friday, August 08, 2008 3:58 PMI still get the same error
-
Friday, August 08, 2008 5:16 PMI'm scheduled to demo a beta release of my software program on monday morning and I have met all the specifications except for the upload of the graphic file. Any help will be greatly appreciated.
-
Friday, August 08, 2008 6:03 PM
Take a look here. It's VB.Net, but translation should be pretty straightforward. Storing Binary Files Directly in the Database Using ASP.NET 2.0
If you've not used VB.Net enough to be able to translate, try this: Convert VB.NET to C#
- Marked As Answer by Michael Sun [MSFT]Microsoft Employee, Moderator Tuesday, August 12, 2008 6:12 AM
-
Friday, August 08, 2008 6:11 PMThank you Way, I did see this before. I'll try it and reply back. Probably respond by tomorrow...going into many meeting right now.
-
Wednesday, September 03, 2008 5:06 PM
For this problem, the following link worked out better:
http:/aspnet.4guysfromrolla.com/articles/120606-1.aspx
but now I receive the following error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 25: Line 26: //Load FileUpload's InputStream into Byte array Line 27: byte[] imageBytes = new byte[UploadedFile.PostedFile.InputStream.Length + 1]; Line 28: UploadedFile.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length); Line 29:
Source File: c:\Documents and Settings\annettew\My Documents\Visual Studio 2005\WebSites\MA-Test\NewDetails.aspx.cs Line: 27
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] NewDetails.DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e) in c:\Documents and Settings\annettew\My Documents\Visual Studio 2005\WebSites\MA-Test\NewDetails.aspx.cs:27 System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArgs e) +99 System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +717 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +429 System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +87 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +109 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +86 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +153 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +172 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4886
- Marked As Answer by technette Friday, September 05, 2008 3:27 PM

