Link to home
Start Free TrialLog in
Avatar of olootu
olootuFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Insert Error

Could anyone please tell me what is wrong with this insert query? I keep getting the error (with the bolded highlited in red):

Incorrect syntax near '`'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '`'.

Source Error:


Line 69:                 con.Open();
Line 70:                SqlCommand cmd = new SqlCommand(sSQL, con);
Line 71:                 cmd.ExecuteNonQuery();
Line 72:              
Line 73:        
 

string ConnStr = "Data Source=sql01.ad.gov.uk\\spur;Initial Catalog=PCN_Payments;User ID=spppppppp;Password=passsss ";
                string sSQL = " INSERT INTO capitapayment(fundcode,fundname,ref,amt,source,rurl,backurl,vatcode,custemail,reconscript,sysref,`when`,`live`) VALUES ('31','Car Penalty Charge Notice','" + pcn.ToString() + "','" + amt + " ','I ',' www.ad.gov.uk ',' " + backurl + "',' F ','','','" + pcn.ToString() + "|" + vrm.ToString() + "',NOW(), 1)";
                SqlConnection con = new SqlConnection(ConnStr);
                con.Open();
               SqlCommand cmd = new SqlCommand(sSQL, con);
                cmd.ExecuteNonQuery();
              
        
        
        
       
        

        //Get the last inserted ID
        string lastID = " SELECT @@IDENTITY as id";
      SqlCommand IDcmd = new SqlCommand(lastID, con);
        DataTable odt = new DataTable();
      SqlDataAdapter oda = new SqlDataAdapter(IDcmd);
         oda.Fill(odt);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I hope that connection string isn't for a live db with the user name and password in it.
Avatar of olootu

ASKER

@lsavidge: The connectionstring is NOT correct. I just left a dummy logindetails.