473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

insert into table error

oledbexception was unhandled....syntax error in insert into statement is the error I get I can edit/update information, delete and everything except for add

the cmdSave code is::::

Dim drNewRow As DataRow = m_dtTable1.NewRow()

With Me
drNewRow("id") = .txtid.Text
drNewRow("Date") = .txtdate.Text
drNewRow("Time") = .txttime.Text
drNewRow("CallSign") = .txtcallsign.Text
drNewRow("Freq") = .txtfreq.Text
drNewRow("Mode") = .txtmode.Text
drNewRow("RST") = .txtrst.Text
drNewRow("Notes") = .txtnotes.Text
drNewRow("QslTX") = .txtqsltx.Text
drNewRow("QslRX") = .txtqslrx.Text
End With

m_dtTable1.Rows.Add(drNewRow)
m_daTable1.Update(m_dtTable1) <<<<-----ERROR HERE

m_intRowPosition = m_dtTable1.Rows.Count - 1

m_blnNewRecord = False
m_blnUpdateRecord = False

ShowCurrentRecord()


----------------------------------------------------------------

declarations:::
Public m_cnTable1 As New OleDb.OleDbConnection
Public m_daTable1 As OleDb.OleDbDataAdapter
Public m_cbTable1 As OleDb.OleDbCommandBuilder
Public m_dtTable1 As New DataTable
Public m_intRowPosition As Integer = 0
Public m_blnNewRecord As Boolean = False
Public m_blnUpdateRecord As Boolean = False


----------------------------------------------------------------

I can post full code if need be but I figured going through that much might be enough
Dec 16 '07 #1
7 1211
Dököll
2,364 Expert 2GB
oledbexception was unhandled....syntax error in insert into statement is the error I get I can edit/update information, delete and everything except for add

the cmdSave code is::::

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim drNewRow As DataRow = m_dtTable1.NewRow()
  3.  
  4. With Me
  5. drNewRow("id") = .txtid.Text
  6. drNewRow("Date") = .txtdate.Text
  7. drNewRow("Time") = .txttime.Text
  8. drNewRow("CallSign") = .txtcallsign.Text
  9. drNewRow("Freq") = .txtfreq.Text
  10. drNewRow("Mode") = .txtmode.Text
  11. drNewRow("RST") = .txtrst.Text
  12. drNewRow("Notes") = .txtnotes.Text
  13. drNewRow("QslTX") = .txtqsltx.Text
  14. drNewRow("QslRX") = .txtqslrx.Text
  15. End With
  16.  
  17. m_dtTable1.Rows.Add(drNewRow)
  18. m_daTable1.Update(m_dtTable1) <<<<-----ERROR HERE
  19.  
  20. m_intRowPosition = m_dtTable1.Rows.Count - 1
  21.  
  22. m_blnNewRecord = False
  23. m_blnUpdateRecord = False
  24.  
  25. ShowCurrentRecord()
  26.  
  27.  
  28. ----------------------------------------------------------------
  29.  
  30. declarations:::
  31. Public m_cnTable1 As New OleDb.OleDbConnection
  32. Public m_daTable1 As OleDb.OleDbDataAdapter
  33. Public m_cbTable1 As OleDb.OleDbCommandBuilder
  34. Public m_dtTable1 As New DataTable
  35. Public m_intRowPosition As Integer = 0
  36. Public m_blnNewRecord As Boolean = False
  37. Public m_blnUpdateRecord As Boolean = False
  38.  
----------------------------------------------------------------

I can post full code if need be but I figured going through that much might be enough
Greetings!

I have not yet handled insert/update commands in his fashion, but one thing I see is should you also dimension daTable1 as you did here:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim drNewRow As DataRow = m_dtTable1.NewRow()
  3.  
  4.  
Also, are you updating to the daTable1 table?

Should you say:

Expand|Select|Wrap|Line Numbers
  1.  
  2. m_daTable1.Rows.Update(m_dtTable1) 
  3.  
  4.  
If nothing is working you might consider adding a different code to add. Something I am actually working on, works great. disregard if your works for you:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim my_database As Database
  3. Dim my_record As Recordset
  4. Set my_database = OpenDatabase("C:\DataGram\Data_Central.mdb")
  5. Set my_record = my_database.OpenRecordset("select * from Employee where Your_Price='" & Text1(0).Text & "'")
  6. my_record.Edit
  7.                 my_record!Your_Price = Text1(0).Text
  8.                 my_record!Name = Text1(1).Text
  9.                 my_record!Crime_Rate_1 = Text1(2).Text
  10.                 my_record!Crime_Rate_2 = Text1(3).Text
  11.                 my_record!Type = Text1(4).Text
  12.  
  13. my_record.Update
  14. my_record.Close
  15. my_database.Close
  16.  
  17. End If
  18.  
  19. End Sub
  20.  
Still try adding Rows.Update to the line mentioned, okay.

In a bit!

Dököll
Dec 16 '07 #2
Dököll
2,364 Expert 2GB
Nevermind, I think you're refering to Insert, you must Add Insert, not Update, so perhaps Rows.Insert, or simply Insert, instead of Update, my apologies. I thought you were having issues updating when I read that portion of the code.

See if that works:-)
Dec 16 '07 #3
I replaced m_dtTable1.Rows.Add(drNewRow) with m_dtTable1.Rows.InsertAt(drNewRow, m_dtTable1.Rows.Count + 1)

still same error


m_daTable1.InsertCommand is the only insert available to me and that doesnt seem to be the right way to go either...thisis sooo frustrating, so close to finishing but yet soo far
Dec 16 '07 #4
Torgg
41
I think you are using reserved words as field names in the database (i.e. "Date" and "Time") try puting square brackets around those two words in your code, like so "[Date]" "[Time]" or you can change the field names (in the database) to somthing like "EventDate" and "EventTime". When using reserved words as field names in a database you have to use square brackets when using those field names in your query/code. There is a long list reserved words, here is a link to a list.

http://support.microsoft.com/kb/286335

Notes: you are also using "Notes" which is not a reserved word but "Note" is also "ID" is not on the list but I imagin it could give you problems. I would recomend (if possable) to change those field names as well. I hope this helps!


Torgg
Dec 16 '07 #5
changed date to ddate same thing will work on the other fields and see how it goes
Dec 16 '07 #6
WOOOHOOO

changed id date time and notes left all other fields the same and bingo worked best kind

leave it to me to pick names that are reserved

thank you soooooooooOOOOOOOOOOOOOOooooooooooooo much, this has been a 2 week battle

thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou
Dec 16 '07 #7
Torgg
41
I'm so glad I could help... take care!
Dec 16 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: ImraneA | last post by:
Hi there Application : Access v2K/SQL 2K Jest : Using sproc to append records into SQL table Jest sproc : 1.Can have more than 1 record - so using ';' to separate each line from each other.
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
6
by: Karen Middleton | last post by:
In MS Access I can do in one SQL statement a update if exists else a insert. Assuming my source staging table is called - SOURCE and my target table is called - DEST and both of them have the...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the INSERT. When I tried to issue a COMMIT, right after...
2
by: harborboy76 | last post by:
Hi, I had posted one topic earlier, but somehow the link has been broken and I cannot see the topic. So sorry if this is a duplicate topic for some. Here is the issue that I'm running into....
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.