Click here to Skip to main content
16,005,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have signup webform and i have written insert query on signup button.
It was working correctly.But i have added fileupload for image uploading and after changing this.My data is not getting inserted.Please help.
Here is my code-


C#
SqlConnection conn = new SqlConnection("Data Source=SNEHAL-PC\\SNEHAL1;Initial Catalog=TEMPRUJU;Integrated Security=True");
        SqlCommand cmd;
 cmd = new SqlCommand("insert into login(name,midname,surname,username,password,contact,dob,email,address,occupation,ltype,image) values('" + txtfirst.Text + "','" + txtmid.Text + "','" + txtsur.Text + "','" + txtname.Text + "','" + txtpass.Text + "','" + txtcontact.Text + "','" + txtdob.Text + "','" + txtemail.Text + "','" + txtaddr.Text + "','" + txtocc.Text + "','" + typeButtonList1.SelectedValue + "','"+image1.ImageUrl+"')", conn);
   cmd.ExecuteNonQuery();
   Response.Redirect("WebForm1.aspx");






C#
protected void btn_upload_Click(object sender, EventArgs e)
        {
            lbl_test.Text = "";
            if (fileimage1.HasFile)
            {
                FileUpload fileupload1 = fileimage1;
                String v_folder = "imageupload/";
                fileupload1.SaveAs(Server.MapPath(v_folder) + fileupload1.FileName);
                image1.ImageUrl = v_folder + fileupload1.FileName;
                String extension;
                extension = Path.GetExtension(image1.ImageUrl);
                if (extension == ".png" || extension == ".PNG" || extension == ".JPEG" || extension == ".jpeg" || extension == ".jpg" || extension == ".JPG" || extension == ".gif" || extension == ".GIF" || extension == ".bmp" || extension == ".BMP" || extension == ".TIF" || extension == ".tif" || extension == ".psd" || extension == ".PSD")
                {
                    lbl_test.Text = "File uploaded successfully";
                }
                else
                {
                    lbl_test.Text = "please upload Image file";
                }

            }
Posted
Updated 14-Feb-14 0:13am
v4
Comments
Gitanjali Singh 14-Feb-14 6:17am    
Put debugger and check value of image1.ImageUrl and also ckeck datatype of column in which you are inserting the value of image url table.
Member 10523130 14-Feb-14 6:56am    
datatype is varchar.and still it is giving me same problem

make sure that the datattype for image is varchar or image as per your requirement place the correct datatype in table
 
Share this answer
 
Comments
Member 10523130 14-Feb-14 6:53am    
datatype for image is varchar.but still it is giving me this problem
Member 10476757 14-Feb-14 7:01am    
are you getting any error, and also in server.mappath try using server.mappath("~") and also insert the correct amount of values in db
Member 10523130 14-Feb-14 7:11am    
no i am not getting any error but data is also not getting inserted.i have checked the values for inserting in database.and i was getting this problem before adding this image file upload.i have just added this field in insert query.and it is not working now.I am not getting where is the problem
First off, stop doing that.
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Particularly in a web environment, where I could destroy your DB from the other side of the world...

Then, when it is re-coded with parameters, add a try...catch block around that code and report or log any problems with as much detail as you can. Until you do that, we can't tell you how to fix it, because we are as much in the dark as you are - but you can run your code...so when you do and get an error message, it should give you a clue as to what is wrong...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900