Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hello,
 
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
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Have a look at the first answer of this question:
http://stackoverflow.com/questions/1258637/insert-dataset-records-in-database[^]
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")
	connection.Open()
 
	' 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!
	adapter.Update(data)
End Using
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 185
2 jlopez788 109
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,589
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.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