Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with INSERT statement 2

Status
Not open for further replies.

Fred48

Programmer
Feb 23, 2004
62
0
0
US
I am getting a message of "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."

The insert is quite lenghtly sixty one fields. Below is part of the code:
strInsert = "INSERT INTO tblResults ([Update Resp code], [TF Resp Code], TGSN, Update500, [Location A]," _
& " [Location Z], [Pulsing A], [Pulsing Z], [Traffic Class], [Traffic Use], Modifier, [Start Date]," _
& " [End Date], [Carrier Id], [New Resp Code]," _
& " [Update501], [Proj Code], [Growth Code A], [Growth Code Z]," _
& " [Treatment Code], [Conv Code], ECCS, [Blkg Obj], [Req Mo], [TS Conv Code]," _
& " [Update502], [A Leg 1], [A Leg 1 Pct Ofl], [A Leg 2], [A Leg 2 Pct Ofl], [A Leg 3], [A Leg 3 Pct Ofl]," _
& " [A Cluster Final]," _
& " [Update503], [Z Leg 1], [Z Leg 1 Pct Ofl], [Z Leg 2], [Z Leg 2 Pct Ofl], [Z Leg 3], [Z Leg 3 Pct Ofl]," _
& " [Z Cluster Final]," _
& " [Update504], [Other TGID]," _
& " [Update505], [Stated Req Trks], [Proj Ratio]," _
& " [Update510], [Trunks In Svc], [Cond Cd], [Cnst Cat], Use, [A Own], [Z Own], [Min Pri CCS], [Mod Eng Code]," _
& " [Stim Fac], [Other Trks], [Other CCS], [Rpt Ex Ind], [TS Resp Code], [Orig TS Resp Code])" _
& " Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

Using cmd As New OleDbCommand(strInsert, cnn)
cmd.CommandText = CommandType.Text."
end etc.
cmd.Parameters.AddWithValue("Orig TS Resp Code", m_DownLoadRequest.OrigTSRespCode)
cmd.ExecuteNonQuery()

I did not include all the fields under the Using cmd.

I am using a similar INSERT but not as many fields and I had not problem.

So, can someone direct me to where I can find more information of this error.

Thanks

 
After you have built your string, add this line of code

Debug.Write(Environment.NewLine & strInsert & Environment.NewLine)

Then, add a breakpoint after you set your query string. Run your program, and when it hits the breakpoint, check the Output window which will have your string. Paste that into your SQL editor or Notepad and look for any syntax errors.
 
.... or you can do (at least in 2008 version) - after executing line of code where you assign the value to your [tt]strInsert[/tt], place your cursor over the variable and click on little magnifying glass icon

str.JPG


Have fun.

---- Andy
 
Good call Andy. That feature is also available in VS2005. If you're using 2003, you can get similar, but lesser functionality by highlighting the variable name, right-clicking and choosing "Quick Watch.
 
Thank both of you for your help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top