Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 October 25th, 2008, 04:39 AM
Authorized User
 
Join Date: Oct 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert the items from DataGridView to Ms Ac

I was trying this code to insert the items from ListView to Ms Access Table, and It works well with me. How can I insert the item from DataGridView to Ms Access?

Code:
Public conn As New OleDbConnection  
("Provider=Microsoft.Jet.OLEDB.4.0;" _& "Data Source =" &   
Application.StartupPath & "\Store.mdb ")  
'Insert the items to DB-  
TBbillsDim cmd As New OleDbCommand
cmd.Connection =conn
conn.Open()  

Dim i As Integer  
For i = 0 To Form2.DataGridView2.Rows.Count - 1   
cmd.CommandText = "INSERT   
INTO TBbills (BMaterial,BKind) VALUES (@BMaterial,@BKind) "   
cmd.CommandType = CommandType.Text   

cmd.Parameters.AddWithValue("@BMaterial",Form2.DataGridView2.Columns...)   
cmd.Parameters.AddWithValue("@BKind", Form2.DataGridView2.Columns...)  
Public conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _& "Data Source =" & Application.StartupPath & "\Store.mdb ")'Insert the items to DB-TBbillsDim cmd As New OleDbCommandcmd.Connection = connconn.Open()Dim i As IntegerFor i = 0 To Form2.DataGridView2.Rows.Count - 1 cmd.CommandText = "INSERT INTO TBbills (BMaterial,BKind) VALUES (@BMaterial,@BKind) " cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue("@BMaterial",Form2.DataGridView2.Columns...) cmd.Parameters.AddWithValue("@BKind", Form2.DataGridView2.Columns...)





Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList value insert to MS DB(DetailsView) yukijocelyn ASP.NET 2.0 Basics 2 August 23rd, 2007 01:32 AM
ASP Insert , MS Access Db tigere Classic ASP Databases 0 November 11th, 2006 08:43 AM
Insert Image to MS-SQL melvik C# 8 June 15th, 2006 09:04 AM
Insert row into MS-ACCESS database ITladybug ADO.NET 1 January 28th, 2006 07:57 AM
"ac" Olivia54 Access VBA 3 July 8th, 2004 11:48 PM





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