Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:48:16+00:00 2026-06-07T09:48:16+00:00

I’m doing an user profile, first the user selects the picture and upload into

  • 0

I’m doing an user profile, first the user selects the picture and upload into a folder with this code, the image is displayed after is uploaded:

protected void btnUpload_Click(object sender, EventArgs e)
{
    // Initialize variables
    string sSavePath;
    string sThumbExtension;
    int intThumbWidth;
    int intThumbHeight;

    // Set constant values
    sSavePath = "images/";
    sThumbExtension = "_thumb";
    intThumbWidth = 160;
    intThumbHeight = 120;

    // If file field isn’t empty
    if (filUpload.PostedFile != null)
    {
        // Check file size (mustn’t be 0)
        HttpPostedFile myFile = filUpload.PostedFile;
        int nFileLen = myFile.ContentLength;
        if (nFileLen == 0)
        {
            lblOutput.Text = "El archivo no fue cargado.";
            return;
        }

        // Check file extension (must be JPG)
        if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
        {
            lblOutput.Text = "El archivo debe tener una extensión JPG";
            return;
        }

        // Read file into a data stream
        byte[] myData = new Byte[nFileLen];
        myFile.InputStream.Read(myData, 0, nFileLen);

        // Make sure a duplicate file doesn’t exist.  If it does, keep on appending an 
        // incremental numeric until it is unique
        string sFilename = System.IO.Path.GetFileName(myFile.FileName);
        int file_append = 0;
        while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
        {
            file_append++;
            sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
                             + file_append.ToString() + ".jpg";
        }

        // Save the stream to disk
        System.IO.FileStream newFile
                = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename),
                                           System.IO.FileMode.Create);
        newFile.Write(myData, 0, myData.Length);
        newFile.Close();

        // Check whether the file is really a JPEG by opening it
        System.Drawing.Image.GetThumbnailImageAbort myCallBack =
                       new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
        Bitmap myBitmap;
        try
        {
            myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));

            // If jpg file is a jpeg, create a thumbnail filename that is unique.
            file_append = 0;
            string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName)
                                                     + sThumbExtension + ".jpg";
            while (System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile)))
            {
                file_append++;
                sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) +
                               file_append.ToString() + sThumbExtension + ".jpg";
            }

            // Save thumbnail and output it onto the webpage
            System.Drawing.Image myThumbnail
                    = myBitmap.GetThumbnailImage(intThumbWidth,
                                                 intThumbHeight, myCallBack, IntPtr.Zero);
            myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile));
            imgPicture.ImageUrl = sSavePath + sThumbFile;


            // Displaying success information
            lblOutput.Text = "El archivo fue cargado con exito!";

            // Destroy objects
            myThumbnail.Dispose();
            myBitmap.Dispose();
        }
        catch (ArgumentException errArgument)
        {
            // The file wasn't a valid jpg file
            lblOutput.Text = "No es un archivo .jpg valido";
            System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));
        }
    }
}

After that the user finish with the other fields of the profile (name, email, etc), there is a save button and is saved into the database with this:

This is the front code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pruebaConnectionString %>"
    InsertCommand="INSERT INTO Curriculum(Nombre, Correo) VALUES (@TextBox1, @TextBox2)">
    <InsertParameters>
        <asp:ControlParameter ControlID="TextBox1" DefaultValue="" Name="TextBox1" PropertyName="Text" />
        <asp:ControlParameter ControlID="TextBox2" DefaultValue="" Name="TextBox2" PropertyName="Text" />                     
    </InsertParameters>
</asp:SqlDataSource>

Actually there are more fields, but to make it short i just copy the first 2, the nombre field is the only that cannot be null on the database

Code behind:

protected void Button1_Click(object sender, EventArgs e)
{
                SqlDataSource1.Insert();

        String strConn = "Data Source=TOSHI;Initial Catalog=prueba;Integrated Security=True";
        SqlConnection conn = new SqlConnection(strConn);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        string strQuery = "Insert into curriculum (imagen) values (@imgPicture)";
        cmd.CommandText = strQuery;
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@imgPicture", (imgPicture.ImageUrl == null ? (object)DBNull.Value : (object)imgPicture.ImageUrl));
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
}

what now i’m trying to do is that when the user clicks the save button (or what is on the method button1_click), the image url is saved into the database on the field Imagen that is a varchar 50, but is not working, i get: Cannot insert the value NULL into column ‘Nombre’, table ‘prueba.dbo.Curriculum’; column does not allow nulls. INSERT fails.
The statement has been terminated.

But if i leave the button1_click method with just SqlDataSource1.Insert(); the fields get saved onto the database.

Any idea how to save the image url onto the database? Hope i’m being clear with my explanation!

Thanks! 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:48:18+00:00Added an answer on June 7, 2026 at 9:48 am

    Are you trying to create a new record (in which canse you need to specify all of the values) or are you tring to update a record?

    At the moment your code is trying to do an INSERT which will create a new record in the curriculum table, but you are only setting the 1 value. Maybe you want to do an UPDATE instead?

    string strQuery = "UPDATE curriculum SET imagen = @imgPicture WHERE Nombre = ???";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.