473,411 Members | 2,030 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,411 software developers and data experts.

oledb date/time insert command format

Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into" command
is incorrect.

Can anyone tell looking at my code what I'm doing wrong or suggest the
correct syntax.

Here is the code I'm using

Imports System.Data.OleDb
Imports System.Data

Public Class myForm

Dim myConnection As OleDbConnection
Dim myCommand As OleDb.OleDbCommand
Dim insertCMD, deleteCMD, updateCMD, insertCMDLogIn, insertCMDLogOut,
selectCMD As String

Private Sub insertRecord()

myConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='C:\myDbase.mdb'")
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond
Oct 16 '06 #1
5 4805
Hi mabond

"mabond" <ma****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into"
command
is incorrect.
<snip/>
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"
Try this INSERT command without the trailing ;

--
SvenC
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond


Oct 16 '06 #2
SvenC

thanks for quicke response, however your suggestion has not resolved the
issue. I'm still receiving a syntax error in "insert into" command

Regards

Michael

"SvenC" wrote:
Hi mabond

"mabond" <ma****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft table I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql database
but I'm getting an error telling me the syntax of the "insert into"
command
is incorrect.
<snip/>
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"

Try this INSERT command without the trailing ;

--
SvenC
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond


Oct 16 '06 #3
Hi mabond,

"mabond" <ma****@discussions.microsoft.comwrote in message
news:53**********************************@microsof t.com...
SvenC

thanks for quicke response, however your suggestion has not resolved the
issue. I'm still receiving a syntax error in "insert into" command
I never used Access and Oledb, so I am just guessing. Here is the next
guess:
I seem to remember that parameters might be declared with a ? in the command
string, so you could try to replace @fone, @ftwo, @fthree with ?, ?, ?
The questionmarks are bound to parameters by position because they do not
have unique names anymore.

You might also have to explicitly state the length of strings you pass.
Though that would rather show up as a problem of data lost on the way to the
DB table and not as runtime error.

--
SvenC
Regards

Michael

"SvenC" wrote:
>Hi mabond

"mabond" <ma****@discussions.microsoft.comwrote in message
news:9A**********************************@microso ft.com...
Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft table
I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql
database
but I'm getting an error telling me the syntax of the "insert into"
command
is incorrect.
<snip/>
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"

Try this INSERT command without the trailing ;

--
SvenC
myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond



Oct 16 '06 #4
Sven

Thanks for this ..... but I'm afraid I've realised what the answer is....and
a silly mistake on my part.....and has led to me wasting your precious time.

To protect my original code I replaced tablenames, fieldnames etc in my post
with "dummy" names. A bad mistake cos you would have spotted the problem
right away.

field3 is actually named in my Access table as DateTime. With that being an
expression for defining a field type it's no wonder that my "insert into"
command was coming back with a syntax error!!

Sorry for leading you an a wild goose chase and I've learned my lesson .....
always post the code being used.

Thanks

Michael Bond

laised the answer

"SvenC" wrote:
Hi mabond,

"mabond" <ma****@discussions.microsoft.comwrote in message
news:53**********************************@microsof t.com...
SvenC

thanks for quicke response, however your suggestion has not resolved the
issue. I'm still receiving a syntax error in "insert into" command

I never used Access and Oledb, so I am just guessing. Here is the next
guess:
I seem to remember that parameters might be declared with a ? in the command
string, so you could try to replace @fone, @ftwo, @fthree with ?, ?, ?
The questionmarks are bound to parameters by position because they do not
have unique names anymore.

You might also have to explicitly state the length of strings you pass.
Though that would rather show up as a problem of data lost on the way to the
DB table and not as runtime error.

--
SvenC
Regards

Michael

"SvenC" wrote:
Hi mabond

"mabond" <ma****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft table
I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql
database
but I'm getting an error telling me the syntax of the "insert into"
command
is incorrect.
<snip/>
insertCMD = "INSERT INTO myTable (field1, field2, field3) VALUES
(@fone, @ftwo, @fthree);"

Try this INSERT command without the trailing ;

--
SvenC

myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond



Oct 16 '06 #5
Hi Michael,

"mabond" <ma****@discussions.microsoft.comwrote in message
news:1A**********************************@microsof t.com...
Sven

Thanks for this ..... but I'm afraid I've realised what the answer
is....and
a silly mistake on my part.....and has led to me wasting your precious
time.

To protect my original code I replaced tablenames, fieldnames etc in my
post
with "dummy" names. A bad mistake cos you would have spotted the problem
right away.

field3 is actually named in my Access table as DateTime. With that being
an
expression for defining a field type it's no wonder that my "insert into"
command was coming back with a syntax error!!

Sorry for leading you an a wild goose chase and I've learned my lesson
.....
always post the code being used.
No problem ;)

--
SvenC
Thanks

Michael Bond

laised the answer

"SvenC" wrote:
>Hi mabond,

"mabond" <ma****@discussions.microsoft.comwrote in message
news:53**********************************@microso ft.com...
SvenC

thanks for quicke response, however your suggestion has not resolved
the
issue. I'm still receiving a syntax error in "insert into" command

I never used Access and Oledb, so I am just guessing. Here is the next
guess:
I seem to remember that parameters might be declared with a ? in the
command
string, so you could try to replace @fone, @ftwo, @fthree with ?, ?, ?
The questionmarks are bound to parameters by position because they do not
have unique names anymore.

You might also have to explicitly state the length of strings you pass.
Though that would rather show up as a problem of data lost on the way to
the
DB table and not as runtime error.

--
SvenC
Regards

Michael

"SvenC" wrote:

Hi mabond

"mabond" <ma****@discussions.microsoft.comwrote in message
news:9A**********************************@microso ft.com...
Hi

VB.NET 2005 Express edition
Microsoft Access 2000 (SP-3)

Having trouble writing an "insert into" command for a Microsoft
table
I'm
accessing through oledb.

I've tried to follow the same principle I'd use if it was an sql
database
but I'm getting an error telling me the syntax of the "insert into"
command
is incorrect.
<snip/>
insertCMD = "INSERT INTO myTable (field1, field2, field3)
VALUES
(@fone, @ftwo, @fthree);"

Try this INSERT command without the trailing ;

--
SvenC

myCommand = New OleDbCommand(insertCMD, myConnection)
myCommand.Parameters.Add(New OleDbParameter("@fone",
OleDbType.Integer))
myCommand.Parameters.Add(New OleDbParameter("@ftwo",
OleDbType.VarChar))
myCommand.Parameters.Add(New OleDbParameter("@fthree",
OleDbType.Date)) '? not sure if this is the correct object type
myCommand.Parameters(0).Value = Me.fonelabel.Text
myCommand.Parameters(1).Value = Me.ftwolabel.Text
myCommand.Parameters(2).Value = Now() 'must insert both date
and
time, not just date

myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub

End class
Any help appreciated

Thanks

Michael Bond



Oct 16 '06 #6

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

Similar topics

2
by: Tatiana Zadiraka | last post by:
I use DB2 8.1 with FixPack 5. In command line for sql I get all DATE columns only in MM-DD-YYYY format. Of course, DATE('20-12-2003') gives me an error SQL0181N The string representation of a...
2
by: Michel R. | last post by:
What`s wrong with this ??? The insert does not add into the database. Using a Winform and Database is sc.mdb Filename is supplier Fields SuppNbr Int64 SuppName String SuppPhone Int64...
11
by: KavvY | last post by:
Hi Can anyone tell me why I get a SQL syntax error with the following code? string strInsert = "INSERT INTO dateEntry (entry, date) VALUES ('test3', '17/08/2004')"; OleDbCommand cmd = new...
1
by: Brian Henry | last post by:
I have an access database, and one of the fields in the table I am inserting into has a date/time data type. What is the correct OleDb data type to insert the date and time that it is at the moment...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
5
by: mabond | last post by:
Hi Having trouble filling a datetime filed in SQL table with a value from an array. The original source is a comma-delimited text file where the date and time values are in two columns. I...
6
by: Mark | last post by:
Hi, i have an application which works with date. The regional settings of the computer (XP prof. dutch version) are set to French (Belgium). Asp.net and Sql server take the short date format of...
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.