How's to update data in ItemUpdating without Image change?

Dear Friends, I could not find the solution for a week about updating image in detailview. The problem when I update without image upload the error is Implicit conversion from data type nvarchar to varbinary(max) is not allowed. 

<asp:TemplateField HeaderText="Photo" SortExpression="Photo">

<EditItemTemplate>

<asp:FileUpload ID="FileUpload1" runat="server" />

<asp:Image ID="Image2" runat="server"

ImageUrl='<%# Eval("EmployeeId", "ShowPicture.aspx?EmployeeId={0}") %>'

Width="200px" />

</EditItemTemplate>

<InsertItemTemplate>

<asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("Photo") %>'></asp:TextBox>

</InsertItemTemplate>

<ItemTemplate>

<asp:Image ID="Image1" runat="server"

ImageUrl='<%# Eval("EmployeeId", "ShowPicture.aspx?EmployeeId={0}") %>'

Width="200px" />

</ItemTemplate>

</asp:TemplateField>

..........................

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:erpdbConnectionString %>"

DeleteCommand="DELETE FROM [Employee] WHERE [EmployeeId] = @EmployeeId"

InsertCommand="INSERT INTO Employee(EmployeeId, EmployeeName, DepartmentId, CompanyId, Photo, Barcode) VALUES (@EmployeeId, @EmployeeName, @DepartmentId, @CompanyId, @Photo, @Barcode)"

SelectCommand="SELECT * FROM [Employee] WHERE ([EmployeeId] = @EmployeeId)"

UpdateCommand="UPDATE Employee SET EmployeeName = @EmployeeName, DepartmentId = @DepartmentId, CompanyId = @CompanyId, Photo = @Photo, Barcode = @Barcode WHERE (EmployeeId = @EmployeeId)">

<SelectParameters>

<asp:QueryStringParameter Name="EmployeeId" QueryStringField="EmployeeId"

Type="String" />

</SelectParameters>

<DeleteParameters>

<asp:Parameter Name="EmployeeId" Type="String" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="EmployeeName" Type="String" />

<asp:Parameter Name="DepartmentId" />

<asp:Parameter Name="CompanyId" Type="Int32" />

<asp:Parameter Name="Photo" />

<asp:Parameter Name="Barcode" />

<asp:Parameter Name="EmployeeId" Type="String" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="EmployeeId" Type="String" />

<asp:Parameter Name="EmployeeName" Type="String" />

<asp:Parameter Name="DepartmentId" />

<asp:Parameter Name="CompanyId" Type="Int32" />

<asp:Parameter Name="Photo" />

<asp:Parameter Name="Barcode" />

</InsertParameters>

</asp:SqlDataSource>

.......................... The code behide

Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating

Dim EmployeePicture As FileUpload = CType(DetailsView1.FindControl("FileUpload1"), FileUpload)

If EmployeePicture.HasFile Then

Dim imageBytes(EmployeePicture.PostedFile.InputStream.Length) As Byte

EmployeePicture.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)

e.NewValues(
"Photo") = imageBytes

Else

e.NewValues("Photo") = e.OldValues("Photo")

End If

End Sub

0
chaiwat
5/5/2009 2:51:17 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1210 Views

Similar Articles

[PageSpeed] 25

Hi

   You are doing at the time of editing the detailview u are selected a file what u have to do is that while updating the details view u want that path or the file to be uploaded inside the database.

   First u have declared in edit item template once u click edit u are selecting a file by using the file upload then u updating it what u have to do is like first copy the file from location to the to location and stream it and save it inside the database.

 http://www.aspnettutorials.com/tutorials/database/Save-Img-ToDB-VB.aspx

http://www.beansoftware.com/ASP.NET-Tutorials/Save-Read-Image-Database.aspx/

http://www.chestysoft.com/upload/demo.asp

http://www.codeproject.com/KB/web-image/ImageBinaryStream.aspx

 http://visualbasic.ittoolbox.com/groups/technical-functional/vb-dotnet-l/update-of-binary-image-stored-in-sql-database-using-vbnet-2008112

 

Thanks

venky

0
venziar
5/5/2009 7:02:56 AM
Reply:

Similar Artilces:

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question is..is it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed!
What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed! I bind the different datasource to the Gridview when I change the node of TreeView, the GridView control always display the same data when I click different the node of TreeView control,why?but I can get the different data in GridView when I click the Button1 or Button2. //-------------------Program Code (You may save it as a ASPX file and run it)--------------------------------<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http:/...

Bind Data to an Image Control not in a Data Presentation Control
I've been searching for two days but I don't really know what to search for.I'm making a site for a photographer.  The Default.aspx page displays Albums by showing a title, image and description from the database table Albums. Click an album to view the contents and it passes the QueryString which is AlbumName.  The ViewAlbum.aspx page uses the QueryString to display an UpdatePanel holding a Large Image and a Repeater full of dynamically filled ImageButtons for thumbs.  Both are from the database table Photos and are retrieved using an ObjectDataSource. Click the ...

second update panel's hidden field data loses when first update panel's procedure clicked
I am using asp.net v2.0 - my ajax enable web site have 2 update panels 1st Update panel updates a hidden field placed in the 2nd update panel - ok hiden fild is get updated edit procedure associated with in the first update panel then again try to read the value from the hidden field (it is database editing procedure, the hidden filed contain the Primary key). but when the edit procedure is clicked, hidden filed looses the data, the following event is get called when edit_procedure() is clicked Protected Sub hfTenantId_ValueChanged(ByVal sender As Object, ByV...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

changing a data bound control's value
I have a GridView that has the following template:<asp:TemplateField HeaderText="Active" SortExpression="Active">                <ItemTemplate>                    <asp:Label ID="Active" runat="server" Text='<%# Bind("Active") %>'></asp:Label>                </It...

Data presentation without a data control
The Gridview and Formview controls provide good functionality in some circumstances but are clumsey in others. As a newbie to .NET I was wondering if its appropriate to do databinding with textboxes and other data controls outside of one of the new data controls (formview, gridview, etc). Or is it a new standard to always use one of the new data controls. If the answer is yes, would you still use an SQLDatasource, or would you set up the connection in code? And, how would you deal with the syntax? In the Formview we have: <asp:TextBox ID="fnameTextBox" runat="server" ...

How to change 'Resolution' without changing 'Status'
Hi, I have a custom 'Resolution' defined like 'More_Info_Needed'. Any developer working on bug and needs more info on that bug, can change the 'Resolution' to 'More_Info_Needed'. But the problem is that these resolutions are tied to 'Status' field. How can I change the 'Resolution' without changing the 'Status'? Thanks, Lax Laxmikant wrote: > I have a custom 'Resolution' defined like 'More_Info_Needed'. Any developer > working on bug and needs more info on that bug, can change the 'Res...

Change data source control's SQL from code
Is the query used by a data source control (I’m using an AccessDataSource) something that I can change programmatically. I have a list where users can select a record to view in more detail. What ends up in the list depends upon how they fill in a search screen. If they enter a postcode they should get one list, if they enter a (non unique) reference number they should get another list. I could create two list pages, but that doesn’t seem very efficient. I’d rather just change the underlying query. Who knows how many options or design changes will be required in the future?   If I can...

User's Name Changed
We are using Groupwise 5.5 I have a user that recently married. I have created a Groupwise alias for the new name, but how do I go about changing the Groupwise Object/User ID and NDS account ID and keep their email account intact? Thanks, J.Jensen Jeff, you can simply rename the Groupwise account. No mail loss. Uwe -- Novell Support Connection Volunteer SysOp Please don't send me support related e-mail unless I ask you to do so. ...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

How to keep user's inputs and uploading images when I change the user control?
Hi, I have a asp.net page. I used AJAX to partially update a part of the page using web user controls, triggered by a button . User can upload image and some text in the we user control. What suggestion can your guys give to me to implement so that : If the user input something and upload some images, and change to another web user control, the new user control keep what the user input and upload? Thanks...

The value's length for key 'data source' exceeds it's limit of '128'.
Hii, When I tried to bind dropdownlist to database by declaring connection string in the code behind file I am getting this error: The value's length for key 'data source' exceeds it's limit of '128'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The value's length for key 'data source' exceeds it's limit of '128'.Source Error: An...

Getting User Control's Control Data
I am building a wizard that will pull opt reports.  Page 1 let's you pick a website you want to work with based on listings in a table.  Page 2 displays which options you can include in your opt report by bit fields in the same table that fills the dropdown on Page1.  Based on which fields get  a 1, user controls are loaded to display the options.  My question is this: How can I get the information on the options the user selects from the individual user controls? I've read up on serialization but I don't know how to capture an event that fires when a page submits a...

Web resources about - How's to update data in ItemUpdating without Image change? - asp.net.presentation-controls

Dave Hawes Blog
Archive - Dave Hawes Blog

Resources last updated: 12/25/2015 1:30:55 AM