Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 13th, 2016, 05:57 AM
Registered User
Join Date: Jul 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert multiple rows using ExecuteNonQuery in vb.net

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:

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));"	

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..

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

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