Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Default7 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         if (!FileUpload1.HasFile) //Validation
        {
            Response.Write("No file Selected"); return;
        }
        else
        {
            string filename = FileUpload1.PostedFile.FileName;

            //convert the image into the byte
            byte[] imageByte = System.IO.File.ReadAllBytes(filename);

            //Insert the Data in the Table
            using (SqlConnection connection = new SqlConnection())
            {
 connection.ConnectionString = ConfigurationManager.ConnectionStrings["lateefconnectionstring"].ToString();

  connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = connection;

                string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department())";


                cmd.CommandText = commandText;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@Surname", SqlDbType.VarChar);
                cmd.Parameters["@Surname"].Value = TxtSurname.Text;
                cmd.Parameters.Add("@Lastame", SqlDbType.VarChar);
                cmd.Parameters["@Lastame"].Value = TxtLastName.Text;
                cmd.Parameters.Add("@username", SqlDbType.VarChar);
                cmd.Parameters["@username"].Value = TxtUsername.Text;
                cmd.Parameters.Add("@Phone", SqlDbType.VarChar);
                cmd.Parameters["@Phone"].Value = TxtPhone.Text;
                cmd.Parameters.Add("@image", SqlDbType.VarBinary);
                cmd.Parameters["@image"].Value = imageByte;
                cmd.Parameters.Add("@Department", SqlDbType.VarChar);
                cmd.Parameters["@Department"].Value = TxtDpt.Text;
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                connection.Close();

                Response.Write("Data has been Added");
            }
        }
    }
    }



I get this below error after running this script kindly help me look into it.

Incorrect syntax near '('. 
   
 
 Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '('.
 
Source Error: 
 

 
Line 53:                 cmd.Parameters.Add("@Department", SqlDbType.VarChar);
Line 54:                 cmd.Parameters["@Department"].Value = TxtDpt.Text;
Line 55:                 cmd.ExecuteNonQuery();  
Line 56:                 cmd.Dispose();  
Line 57:                 connection.Close(); 
Posted
Comments
[no name] 18-Jul-14 14:05pm    
You should go back and read the answers you already have to this exact same "question".

1 solution

Look at your code:
C#
string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department())";
Why are you trying to INSERT to a function?
Try removing the brackets:
C#
string commandText = "Insert into users values (@Surname,@Lastame,@username,@Phone,@image,getdate,@Department)";
 
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