473,394 Members | 1,878 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,394 software developers and data experts.

Problem with INSERT INTO MS Access using VB.NET

All,
I am attempting to insert a new row into an MS Access database using
VB.NET. This is an existing access database that I did not create, so I do
not know all of the field properties. I have used VB.NET in the past, but
never for database applications. When I run the following code I recieve the
error:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

This error occurs at the line:

"temp_num = myOleDbCommand.ExecuteNonQuery"


Here is the code and thank you for your help in advance:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myOleDbConnection As OleDb.OleDbConnection

Dim insertcommand As String

Dim myConnectionString As String = _

"Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=T:\project_tracking\project database\Copy of projects.mdb;" & _

"User ID=Admin;" & _

"Password="

insertcommand = "INSERT INTO Contacts (ProjNum, ContactCode, FirstName,
LastName, WorkPhone, Email, Pager, Source, Responsibility, LastMaintDate)
VALUES ('202-MV174', '0', 'Brenton', 'Kemmer', '248-830-1532', 'None', 'Na',
'Na', 'here', '2004-10-19 10:25:38')"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertcommand,
myOleDbConnection)

myOleDbConnection.Open()

Dim temp_num As Integer

temp_num = myOleDbCommand.ExecuteNonQuery

myOleDbConnection.Close()

End Sub
Thanks
--
kemmerc2 - forum member
http://www.visual-basic-data-mining.net/forum
Nov 21 '05 #1
2 10339
Hi,

There is an error with sql statement. Place the update command in a
try catch block to get a better message. This code will display the error
message in the output window

myOleDbConnection.Open()

Dim temp_num As Integer

Try

temp_num = myOleDbCommand.ExecuteNonQuery

catch ex as exception
trace.writeline(ex.tostring)
end try

myOleDbConnection.Close()

Ken
-------------------------------
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:O3**************@TK2MSFTNGP12.phx.gbl...
All,
I am attempting to insert a new row into an MS Access database using
VB.NET. This is an existing access database that I did not create, so I do
not know all of the field properties. I have used VB.NET in the past, but
never for database applications. When I run the following code I recieve the
error:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

This error occurs at the line:

"temp_num = myOleDbCommand.ExecuteNonQuery"


Here is the code and thank you for your help in advance:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myOleDbConnection As OleDb.OleDbConnection

Dim insertcommand As String

Dim myConnectionString As String = _

"Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=T:\project_tracking\project database\Copy of projects.mdb;" & _

"User ID=Admin;" & _

"Password="

insertcommand = "INSERT INTO Contacts (ProjNum, ContactCode, FirstName,
LastName, WorkPhone, Email, Pager, Source, Responsibility, LastMaintDate)
VALUES ('202-MV174', '0', 'Brenton', 'Kemmer', '248-830-1532', 'None', 'Na',
'Na', 'here', '2004-10-19 10:25:38')"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertcommand,
myOleDbConnection)

myOleDbConnection.Open()

Dim temp_num As Integer

temp_num = myOleDbCommand.ExecuteNonQuery

myOleDbConnection.Close()

End Sub
Thanks
--
kemmerc2 - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #2
Wrap your date/time values inside # for quoting instead of ' i.e.
#2004-10-19 10:25:38#.
You may also need to quote the field name Source as [Source] as this may
be a reserved word for the OleDb driver.
For more specific responses about ADO.NET see
microsoft.public.dotnet.framework.adonet.

Ron Allen
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:O3**************@TK2MSFTNGP12.phx.gbl...
All,
I am attempting to insert a new row into an MS Access database using
VB.NET. This is an existing access database that I did not create, so I do
not know all of the field properties. I have used VB.NET in the past, but
never for database applications. When I run the following code I recieve
the
error:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll

This error occurs at the line:

"temp_num = myOleDbCommand.ExecuteNonQuery"


Here is the code and thank you for your help in advance:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myOleDbConnection As OleDb.OleDbConnection

Dim insertcommand As String

Dim myConnectionString As String = _

"Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=T:\project_tracking\project database\Copy of projects.mdb;" &
_

"User ID=Admin;" & _

"Password="

insertcommand = "INSERT INTO Contacts (ProjNum, ContactCode, FirstName,
LastName, WorkPhone, Email, Pager, Source, Responsibility, LastMaintDate)
VALUES ('202-MV174', '0', 'Brenton', 'Kemmer', '248-830-1532', 'None',
'Na',
'Na', 'here', '2004-10-19 10:25:38')"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)

Dim myOleDbCommand As New OleDb.OleDbCommand(insertcommand,
myOleDbConnection)

myOleDbConnection.Open()

Dim temp_num As Integer

temp_num = myOleDbCommand.ExecuteNonQuery

myOleDbConnection.Close()

End Sub
Thanks
--
kemmerc2 - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #3

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

Similar topics

3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
2
by: Lyn | last post by:
I am trying to embed a picture into a Bound Object Frame (Me!Photograph) with the following code which is based on MS article http://support.microsoft.com/?id=158941: strPathname =...
0
by: Lyn | last post by:
I am having a frustrating time trying to do a simple insert of a BMP picture into a Bound Object Frame using both VBA and the Insert | Object... dialog. I had a separate post thread going on this...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
22
by: b_r | last post by:
Hi, I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL Server. The code is as follows: Dim sConnectionString As String = _ "Data...
8
by: John | last post by:
Hi I am using the below code to run a sql on an underlying access table; insStr = "INSERT INTO ( Action, , , Request_Date ) " & _ "VALUES (""Modify Client"", 93, ""Administrator"", Now())"...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
0
by: fig000 | last post by:
Hi, I'm using an objectdatasource. The insert procedure called by the objectdatasource is in a separate library file outside of the aspx and the codebehind that is using the objectdatasource in...
4
by: Neil | last post by:
Having trouble with inserting a record into a table. It's a list of names. But, for some reason, it won't take a particular name. When a user tries to enter a name into the table, the system hangs...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...

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.