[Solved] ASP.Net Uploading File Error: incorrect syntax near file

Last Reply 4 months ago By itsme

Posted 4 months ago

I am trying to upload resume of user when it is giving me error of "incorrect syntax near file".

I want to upload resume of user if user has not filled his profile information and if user profile information is already in table then only update button should be visible to user and data should be  filled in textbox.

protected void btnsave_Click(object sender, EventArgs e)
    int i = 0;
    string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
    Stream str = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(str);
    Byte[] size = br.ReadBytes((int)str.Length);
    string constr = ConfigurationManager.ConnectionStrings["Q_SS_regnConnectionString1"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
        using (SqlCommand cmd = new SqlCommand("Insert into Job_Seeker_Profile (Name,Address,Contact,email,tenth,twelve,graduate,file,Qualification) Values (@Name,@Address,@Contact,@email,@tenth,@twelve,@graduate,@file,@Qualification)", con))
            //cmd.Parameters.AddWithValue("@Id", Id.Value);
            cmd.Parameters.AddWithValue("@Name", jsname.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@Address", txt_add.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@Contact", txt_no.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@email", txt_email.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@tenth", txt_tenth.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@twelve", txt_twelve.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@graduate", txt_graduate.Text.Trim().ToString());
            cmd.Parameters.AddWithValue("@file", size);
            cmd.Parameters.AddWithValue("@Qualification", txt_quali.Text.Trim().ToString());
            i = cmd.ExecuteNonQuery();
            lblMessage.Text = "Saved Successfully.";

in this line i = cmd.ExecuteNonQuery(); 

CREATE TABLE [dbo].[Job_Seeker_Profile] (    
[Id]            INT          NOT NULL,    
[Name ]         VARCHAR (50) NULL,    
[Address]       VARCHAR (50) NULL,    
[Contact]       VARCHAR (50) NULL,    
[email]         VARCHAR (50) NULL,    
[tenth]         VARCHAR (50) NOT NULL,    
[twelve]        VARCHAR (50) NOT NULL,    
[graduate]      VARCHAR (50) NOT NULL,    
[file]          varBinary(MAX) NOT NULL,    
[Qualification] VARCHAR (50) NULL,    


You are viewing reply posted by: itsme 4 months ago.
Posted 4 months ago

Ya you are right actually in database i had written file so in sql file is already a function so thats why it is creating problem so by renaming it my issue got solved.

Thanks a lot.