Datagrid and SQL

I am trying to save the datagrid to an access database. I am new to VB 6 and i'm not quite sure how to do this. I would like to use SQL statements. Can someone help me with this?
[186 byte] By [lwikert] at [2007-11-20 8:26:10]
# 1 Re: Datagrid and SQL
This is how you add records to an Access database using SQL - however you need to populate variables from your Grid before INSERTING

Have a look here to show you how to interate through a grid

http://www.dev-archive.com/forum/showthread.php?t=424964

(The examples are in the on-line help of VB6, by pressing F1 when highlighting INSERT)

This example selects all records in a hypothetical New Customers table and adds them to the Customers table. When individual columns are not designated, the SELECT table column names must match exactly those in the INSERT INTO table.

Sub InsertIntoX1()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Select all records in the New Customers table
' and add them to the Customers table.
dbs.Execute " INSERT INTO Customers " _
& "SELECT * " _
& "FROM [New Customers];"

dbs.Close

End Sub

This example creates a new record in the Employees table.

Sub InsertIntoX2()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Create a new record in the Employees table. The
' first name is Harry, the last name is Washington,
' and the job title is Trainee.
dbs.Execute " INSERT INTO Employees " _
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"

dbs.Close

End Sub

Another way to do this example, which is how you will do it from the grid could be ...

Lets say you have passed data from the grid, to variables

EmpFirstName, EmpLastName, EmpTitle

Sub InsertIntoX2()

Dim dbs As Database

' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")

' Create a new record in the Employees table. The

dbs.Execute " INSERT INTO Employees " _
& "(FirstName,LastName, Title) VALUES " _
& "(EmpFirstName, EmpLastName, EmpTitle);"

dbs.Close

End Sub
George1111 at 2007-11-9 19:38:20 >