473,387 Members | 3,801 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,387 software developers and data experts.

Problems INSERTing into MS Access from VB.NET...

Using VS2003, VB.NET,
Here's some pseudo code that I'm trying to get to work...

if <a specific record existsthen
do nothing
else
<insert the specific record>
Endif

I've got the code written, but Its not working for me...
1. when I check for the existence of the record, I always get False (even if
the record does exist) -- in the code below: the dataset returned from
GetOleDbDataSet in function RecordExist always contains 0 as the result from
the SELECT count(*).SQL -- even when I manually add a record to the actions
table. What am I doing wrong here?
2. related to #1. If I find that the record does not exist, I INSERT it
using an InsertCommand (in the AddRecord sub), then call the RecordExist
function have it return zero again. But when I open Access I verify that the
record exists. Seems like my connection to the database not picking up the
changes... I would not expect this because I am creating new connection
objects with each call to RecordExist... any idea what I'm missing here?
3. Unrelated to 1,2... when I open my connection to the MS Access mdb, I
get, as expected, a lock file (ldb). The problem is that when I dispose of
and close the adapters & connection objects, the lock file persists. Then
when I go to manually open the mdb, I'm get a message stating that the mdb is
exclusively locked... ??

Any pointer's to examples, answers or feedback on my issues would be
appreciated. See code snippets below.

Thanks for your attention to this matter.

Here are the functions & subs I wrote to accomplish my (simple) task:
'Implementation of pseudo code...
If RecordExist() Then 'Do nothing
Else
AddRecord()
End If

Public Function RecordExist() As Boolean
RecordExist = False
Dim ds As DataSet
Try
ds = GetOleDbDataSet(strConnection, _
"SELECT Count(*) FROM Actions WHERE Pk=1") 'Pk=primary key
on Actions table
If Int64.Parse(ds.Tables(0).Rows(0).Item(0).ToString) 0 Then
RecordExist = True
End If
Catch ex As Exception
ds.WriteXml(System.Console.Out)
End Try
End Function

Public Sub AddRecord()
Try
Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim cmd As OleDbCommand
Dim conn As New OleDbConnection(strConnection)
cmd = New OleDbCommand( _
"INSERT INTO Actions (Pk) VALUES (1)", conn)
da.InsertCommand = cmd
conn.Open()
da.InsertCommand.ExecuteNonQuery()
conn.Close()
da.Dispose()
conn = Nothing
cmd = Nothing
da = Nothing
Catch ex As Exception
Stop
End Try
End Sub

Public Function GetOleDbDataSet(ByVal strConn As String, ByVal strSQL As
String) As DataSet
Try
Dim conn As New OleDbConnection(strConn)
Dim adapter As New OleDbDataAdapter
Dim dataSet As New DataSet
adapter.SelectCommand = New OleDbCommand(strSQL, conn)
adapter.Fill(dataSet)
conn.Close()
adapter.Dispose()
conn = Nothing
adapter = Nothing
Return dataSet
Catch ex As Exception
Return Nothing
End Try
End Function
Jul 20 '06 #1
0 1157

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

Similar topics

0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
3
by: Eric Lilja | last post by:
Hello, I'm creating a small utility for an online game. It involves parsing a text file of "tradesskill recipes" and inserting these recipes in a gui tree widget (similar to gui file browsers if...
3
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when...
1
by: B Moor | last post by:
Hello, I am quite bogged down with this problem and would like some tips/help if any one has any. Thanks in advance. The Problem ----------- This system initially seemed quite stable for...
1
by: Andreas | last post by:
Hi, we have some problems with the following situation: A remote application A writes files to a directory monitored by a FileSystemWatcher-instance in application B. A creates the file with...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
4
by: Richard Finnigan | last post by:
Hi I'm having real difficulties getting a very simple access database file to show its data in visual studio data controls with various error messages occuring. I've changed the permissions on...
0
by: tom c | last post by:
I am going through "Walkthrough: Editing and Inserting Data in Web Pages with the DetailsView Web Server Control" found at http://msdn2.microsoft.com/en-us/library/sdba1d59.aspx I am using...
5
LAD
by: LAD | last post by:
Using Access 2003 on Windows 2000. My Skill Level: Med Low (Some VBA, okay with Access) Form: Single View - based on Query of single Table to sort by field. Application: Dealers email 'contract...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.