473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error With Insert

I am having a problem, inserting 4 items into a database table.

The database table simply consists of 4 records:

Date
Com
Note
Name

All fields are of type 'Text'

Here is my sub:

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim sqlString As String
sqlString = "Insert Into NOTES (DATE, COM, NOTE, NAME) Values (" _
& "'" & Now().ToString & "', " _
& "'" & Form3.CName.Text & "', " _
& "'" & txtNotes.Text & "', " _
& "'" & txtName.Text & "')"
MsgBox(sqlString)
Try
Dim dbConn As OleDbConnection
Dim dbCommand As New OleDbCommand
dbConn = New OleDbConnection(pPROVIDER & pDataSource)
dbCommand.CommandText = sqlString
dbCommand.Connection = dbConn
dbConn.Open()
Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader
dbConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Error")
End Try
End Sub

When I execute this sub, I get the following error:

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at WindowsApplication1.Form4.cmdAdd_Click(Object sender, EventArgs e) in
\Forms\Form4.vb:line 181
Its probably a stupid error on my part. But for the life of my I am having
trouble tracking it down.
Can anyone help?
Dec 5 '05 #1
4 967
Materialised,

We have seen this done in many way, however you are the winner.

You cannot use reserved keywords in a SQL string.

Cor
Dec 5 '05 #2
Thanks for that info. I wasn't aware of that to be honest.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:ec****************@TK2MSFTNGP14.phx.gbl...
Materialised,

We have seen this done in many way, however you are the winner.

You cannot use reserved keywords in a SQL string.

Cor

Dec 5 '05 #3
Hi,

You will not get any records back when you execute your query.
Do not use a datareader.

Replace

Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader

With
dbCommand.ExecuteNonQuery

Ken
--------------------

"Materialised" <ma**********@privacy.net> wrote in message
news:3v*************@individual.net...
I am having a problem, inserting 4 items into a database table.

The database table simply consists of 4 records:

Date
Com
Note
Name

All fields are of type 'Text'

Here is my sub:

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
Dim sqlString As String
sqlString = "Insert Into NOTES (DATE, COM, NOTE, NAME) Values (" _
& "'" & Now().ToString & "', " _
& "'" & Form3.CName.Text & "', " _
& "'" & txtNotes.Text & "', " _
& "'" & txtName.Text & "')"
MsgBox(sqlString)
Try
Dim dbConn As OleDbConnection
Dim dbCommand As New OleDbCommand
dbConn = New OleDbConnection(pPROVIDER & pDataSource)
dbCommand.CommandText = sqlString
dbCommand.Connection = dbConn
dbConn.Open()
Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader
dbConn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Error")
End Try
End Sub

When I execute this sub, I get the following error:

at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32
hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at WindowsApplication1.Form4.cmdAdd_Click(Object sender, EventArgs e) in
\Forms\Form4.vb:line 181
Its probably a stupid error on my part. But for the life of my I am having
trouble tracking it down.
Can anyone help?

Dec 5 '05 #4

well not completely true ,,,, you can as long as you put brackets around
these words like [Date] :-)

although it is ofcourse recomend coding practice to avoid words that are on
the reserved words list

most databases use the SQL 92 reserved words list

http://msdn.microsoft.com/library/de...ra-rz_9oj7.asp

regards

Michel Posseth [MCP]
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:ec****************@TK2MSFTNGP14.phx.gbl...
Materialised,

We have seen this done in many way, however you are the winner.

You cannot use reserved keywords in a SQL string.

Cor

Dec 5 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jason | last post by:
Is there an elegant way to check for the REFERENTIAL INTEGRITY VIOLATION in Access via ASP. The reason I ask is that if the user attempts to refresh the screen after implementing an INSERT he will...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
0
by: Janning Vygen | last post by:
Hi, i have a question about how to handle postgresql constraint errors in the client app. I found some mails in the archive about it, too. But i have still so many questions about how to do it,...
2
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
17
by: pbd22 | last post by:
hi. i keep getting this error. as i understand it, my xml isn't formatted correctly. the online errata suggests the standard formatting to solve this problem: element (tab) (tab) element
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...
10
by: Rahul Babbar | last post by:
Hi, I am getting the following error, while executing the simple insert script on a few tables. INSERT INTO <table_name>(<col1>) VALUES (1); DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884,...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.