Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 13th, 2016, 05:57 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert multiple rows using ExecuteNonQuery in vb.net

Hi,
Newbie here and hoping this is the correct forum for my problem.

I'm trying to insert multiple rows to a table. If I run the query inside Access it first asks for confirmation and then it successfully adds the rows.

However, if I run the same sql string inside VB.net it does not add any row. Here's the code:

Code:
Dim strsql As String = "INSERT INTO tbl_ImagesDetails ( ImageID )
SELECT tbl_Images.ImageID
FROM tbl_Images LEFT JOIN tbl_ImagesDetails ON tbl_Images.[ImageID] = tbl_ImagesDetails.[ImageID]
WHERE (((tbl_Images.ImageID) Like 'ZOOMED*') 
AND ((tbl_ImagesDetails.ImageID) Is Null));"	
	
Debug.Print(strsql)

Dim MyConn As New OleDbConnection(connString)
Dim cmd As New OleDbCommand(strsql, MyConn)
cmd.CommandType = CommandType.Text

If Not MyConn.State = ConnectionState.Open Then MyConn.Open()

Dim iResult As Integer = cmd.ExecuteNonQuery()
Return iResult
What it does:
The code above first checks for unmatched ImageID from the Images table against the ImageDetails table. Any ImageID that's missing in the details table is then added.

I use the same code pattern when inserting only single record and they run well.

My questions:

1. Is the confirmation dialog getting in the way? If so how do I override using vb code?

2. Does ExecuteNonQuery() allow inserting multiple rows in one go?

Any help would be appreciated, thanks. My apologies if I posted in the wrong place.

Last edited by idunnno; July 13th, 2016 at 06:05 AM..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert multiple records from datagridview to ms access database using vb.net hasnain-ahmad BOOK: Professional Visual Basic 2010 and .NET 4 0 April 3rd, 2015 02:04 AM
INSERT multiple rows to a table nvillare Oracle 7 November 3rd, 2007 04:47 AM
INSERT Multiple rows to database melkin Classic ASP Professional 3 April 10th, 2007 09:03 AM
VB.NET ExecuteNonQuery() command Lofa SQL Server 2000 1 September 20th, 2005 10:03 AM
Copying Multiple Rows in MS Excel 2K using VB .Net Azhar Akbari Excel VBA 2 January 27th, 2005 10:04 AM



All times are GMT -4. The time now is 02:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.