Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
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 Smile | :)
Posted 18-Nov-12 3:18am
Edited 18-Nov-12 3:19am
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
0 Sergey Alexandrovich Kryukov 550
1 mhegazy94 460
2 Ravi Bhavnani 230
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,295
1 OriginalGriff 6,841
2 CPallini 5,420
3 George Jonsson 3,654
4 Gihan Liyanage 2,797

Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
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