Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
SQLInsertCommand = "INSERT INTO " & strFileName2 & "_ 
 (TRANDATE,[HOUR],SALES,TRANCNT,TENTNAME,TERMNUM) " & _
 " VALUES('" & Format(CDate(dr("dateid")), "Short Date").ToString & _
 "','" & "" & dr("dhour") & "'," & _
 Format(dr("amt"), "########0.00;-########0.00") & "," _
 & Val("" & dr("ctrno")) & ",'" & _
 LeftX(TenantCode & "-" & TerminalNumber, 15) & "'," & _
 "" & dr("tenantcode") & ")"
                
Dim cmd1 As New OleDb.OleDbCommand(SQLInsertCommand, dBaseConnectionB)
                
cmd1.ExecuteNonQuery()


Error:
The INSERT INTO statement contains the following unknown field name: 'HOUR'. Make sure you have typed the name correctly, and try the operation again.


What I have tried:

I had used also the backticks(`), but still I got the same error.
Posted
Updated 4-Nov-23 4:46am
v2

The error message is clear that tha column name 'HOUR' is not being recognized in the table or not spelled correctly, you are trying to insert data into.
The INSERT INTO statement contains the following unknown field name: 'HOUR'. Make sure you have typed the name correctly
Try to use parameterized queries will help mitigate SQL injection risks and make the code more readable and maintainable instead of string concatenation.
 
Share this answer
 
Just to reinforce the point that may have been missing, that is some horrifyingly bad code. It's near impossible for a newb to debug, isn't supportable n any environment, and would give code and security reviewers heart attacks.

Google for "Sql injection attack" to find out why your code is so bad and what can be done about it.

Use parameterized queries and you get closer to solving all of those problems. Google for "VB.NET Parameterized queries" for more information on how to do this.
 
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