Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting an image file in File System
    primarykey
    data
    text
    <p>I am getting this error:</p> <p>Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.</p> <p>Mine Code is as follows:</p> <p><strong>source code :</strong></p> <pre><code>&lt;asp:ListView ID="ListView1" runat="server" DataKeyNames="UserId" DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" &gt; &lt;InsertItemTemplate&gt; &lt;asp:TextBox ID="UserPicUrlTextBox" runat="server" Text='&lt;%# Bind("UserPicUrl") %&gt;' /&gt; &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt; &lt;asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" /&gt; &lt;asp:Button ID="CancelButton" runat="server" CausesValidation="false" CommandName="Cancel" Text="Clear" /&gt; &lt;/InsertItemTemplate&gt; &lt;/asp:ListView&gt; </code></pre> <p>Mine Insert Parameters are:</p> <pre><code>&lt;InsertParameters&gt; &lt;asp:Parameter Name="UserId" Type="Object" /&gt; &lt;asp:Parameter Name="Category" Type="String" /&gt; &lt;asp:Parameter Name="Class" Type="Int32" /&gt; &lt;asp:Parameter Name="UserPicUrl" Type="String" /&gt; . . &lt;/InsertParameters&gt; </code></pre> <p><strong>c# :</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; public partial class userProfile : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { // Get a reference to the currently logged on user MembershipUser currentUser = Membership.GetUser(); // Determine the currently logged on user's UserId value Guid currentUserId = (Guid)currentUser.ProviderUserKey; // Assign the currently logged on user's UserId to the @UserId parameter e.Command.Parameters["@UserId"].Value = currentUserId; } protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e) { FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1"); string virtualFolder = "~/UserPics/"; string physicalFolder = Server.MapPath(virtualFolder); string fileName = Guid.NewGuid().ToString(); string extension = System.IO.Path.GetExtension(FileUpload1.FileName); FileUpload1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension)); string UserPicUrl = virtualFolder + fileName + extension; e.Command.Parameters["@UserPicUrl"].Value = UserPicUrl; } } </code></pre> <p>Objective: I am trying to store an image in a folder and save the corresponding Url in the db.</p> <p>Will be a great help.Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload