Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Professional C# 4.0 and .NET 4
| Search | Today's Posts | Mark Forums Read
BOOK: Professional C# 4.0 and .NET 4
This is the forum to discuss the Wrox book Professional C# 4.0 and .NET 4 by Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner; ISBN: 9780470502259
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 4.0 and .NET 4 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 September 29th, 2012, 12:35 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert multiple rows from datagridview to table

hi friends
I am new to vb.net , I am having difficulty to insert two rows in database table from datagridview. I can insert one row , I would like to know how do i run nonqueryCommand.Parameters inside For Each loop twice to insert two row. please help me


  Dim thisConnection As New OleDbConnection("Provider=Microsoft.ACE.… Source=C:\Dtb.accdb")

'Create Command object
Dim nonqueryCommand As OleDbCommand = thisConnection.CreateCommand()

' Open Connection
Console.WriteLine("Connection Opened")

' Create INSERT statement with named parameters
nonqueryCommand.CommandText = _
"INSERT INTO myTable (Col1, Col2) VALUES (@Col1, @Col2)"

' Add Parameters to Command Parameters collection
nonqueryCommand.Parameters.Add("@Col1"… OleDbType.VarChar, 50)
nonqueryCommand.Parameters.Add("@Col2"… OleDbType.VarChar, 50)

' Prepare command for repeated execution

' Data to be inserted
For Each row As DataGridViewRow In DataGridView1.Rows
If Not row.IsNewRow Then
nonqueryCommand.Parameters("@Col1").Va… = row.Cells(0).Value.ToString
nonqueryCommand.Parameters("@Col2").Va… = row.Cells(1).Value.ToString
End If


Catch ex As OleDbException
' Display error
Console.WriteLine("Error: " & ex.ToString())
' Close Connection
Console.WriteLine("Connection Closed")

End Try

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To insert DataGridView Data To a New Table? bex Visual Studio 2008 0 June 27th, 2009 03:09 PM
About Insert Multiple Rows of GridView to Databas divekar.vishal ASP.NET 2.0 Professional 0 April 30th, 2008 12:28 AM
INSERT multiple rows to a table nvillare Oracle 7 November 3rd, 2007 04:47 AM
INSERT Multiple rows to database at one time melkin Classic ASP Databases 19 April 11th, 2007 08:22 AM
INSERT Multiple rows to database melkin Classic ASP Professional 3 April 10th, 2007 09:03 AM

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