I have a datagridview which contains 4 records.
I want to insert these records into access table.This access table already have records.
Datagridview's columns & access table's columns are same (datatype & columnname)
How can i insert these 4 records in access table???
Plz anybody help me..............

Thanks in advance...

Recommended Answers

All 2 Replies

It should be something along the lines of this:

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\NorthWind.mdb"
Dim dbConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
dbConnection.open()

For Each DR In DS.Tables(0).Rows
    Dim queryString As String = "INSERT INTO table_name (Field1, Field2, Field3, Field4) VALUES ('" & DR.Item(0) & "', '" & DR.Item(1) & "', '" & DR.Item(2) & "', '" & DR.Item(3) & "')"
    Dim dbCommand As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand(queryString, dbConnection)    
    dbCommand.ExecuteNonQuery()
Next

dbConnection .Close()

You might have to make some adjustments to suite your needs, but I think the idea is more or less to:

  1. Open a connection to your access database
  2. Loop through the grid's rows and inserting them one by one
  3. Closing the connection

Thank you Jackass.It's working.Thank u so much.

Can you plz tell me how to handle datagridviewcombox's event.
I have a datagrid which contains 3 combobox.
I want ,When i clicked 1st combo data should be filtered in 2nd combo.
Is it possoble in datagrid????
I think u can answer my question.
Plz help me.........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.