Click here to Skip to main content
12,830,643 members (41,434 online)
Rate this:
Please Sign up or sign in to vote.

I Searched the internet to use the OleDbAdapter to insert a dataset into my database but until now i came out with nothing.

can anyone please tell me the way to do it

PS: Don't want to spend lots of time looping through the rows while inserting, i need something like Adapter.Update(DataSet1,"Items") or something close to it, please :)
Posted 18-Nov-12 4:18am
Updated 18-Nov-12 4:19am
m a suresh 15-Jun-16 5:44am
how to insert rows into a database table from a dataset ?
Please help..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Have a look at the first answer of this question:[^]
The answer is C# code, this is the same code converted in VB.NET:
' Prerequisite: The data to be inserted is available in a DataTable/DataSet.
Dim data = New DataTable()
data.Columns.Add("CompanyName", GetType(String))
data.Columns.Add("Phone", GetType(String))
data.Rows.Add("Foo", "12345678")
data.Rows.Add("Bar", "87654321")

' Now, open a database connection using the Microsoft.Jet.OLEDB provider.
' The "using" statement ensures that the connection is closed no matter what.
Using connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=Northwind.mdb")

	' Create an OleDbDataAdapter and provide it with an INSERT command.
	Dim adapter = New OleDbDataAdapter()
	adapter.InsertCommand = New OleDbCommand("INSERT INTO Shippers (CompanyName, Phone) VALUES (@CompanyName , @Phone)", connection)
	adapter.InsertCommand.Parameters.Add("CompanyName", OleDbType.VarChar, 40, "CompanyName")
	adapter.InsertCommand.Parameters.Add("Phone", OleDbType.VarChar, 24, "Phone")

	' Hit the big red button!
End Using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100