VB icon

ADODBRecordSet To DataSet

Email
Submitted on: 1/2/2015 6:30:00 AM
By: marisol gonzalez (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB.NET, ASP.NET
Views: 1606
 
     Transform an ADODB.RecordSet to DataSet.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: ADODBRecordSet To DataSet
// Description:Transform an ADODB.RecordSet to DataSet.
// By: marisol gonzalez (from psc cd)
//
// Assumes:1. Create a New Project Windows (Select a Windows Application)
2. You need a DataGrid ,Imports System.Data.OleDb and Imports ADODB. 
3. Copy and paste code at form.
//**************************************

Imports System.Data.OleDb
Imports ADODB
Public Class Form1
 Inherits System.Windows.Forms.Form
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RecordSetToDataSet("ser_amp_bd2", "pubs")
 End Sub
 Private Function RecordSetToDataSet(ByVal Server As String, _
ByVal DataBase As String)
Dim cnn As Connection = New ADODB.Connection()
Dim rs As Recordset = New ADODB.Recordset()
'--Open connection--
cnn.open("PROVIDER=SQLOLEDB;DATA SOURCE=" & Server & ";" & _
 "INITIAL CATALOG=" & DataBase & ";INTEGRATED SECURITY=SSPI;")
'--create recordset--
'--<any table> name of table in your database
Dim sql As String = "select * from authors"
rs.open(sql, cnn, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, 0)
Dim dadapter As New OleDbDataAdapter()
Dim ddataset As New DataSet()
'--Move rs to dataset--
dadapter.Fill(ddataset, rs, "result")
'--Fill a grid--
grd.DataSource = ddataset.Tables("result")
'--Close Connection--
cnn.Close()
 End Function
End Class


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.