olootu
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.SqlE xception: 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:
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.SqlE
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);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I hope that connection string isn't for a live db with the user name and password in it.
ASKER
@lsavidge: The connectionstring is NOT correct. I just left a dummy logindetails.