Click to See Complete Forum and Search --> : How to connect
samikaraeen
Aug 14th, 2002, 12:22 AM
Hi
can u tell me how to connect :
1)Access dat base with vb.net via Ado
2)Mysql datbase " " " " " " " " "
3)Oracle database
Varadero
Aug 14th, 2002, 02:44 AM
This is how I connect to an Access-database, i don't think it will be much different from connecting to another database.
'-------------------------------------------------------------------------------
'Usage : Constructor
'Parameters : -
'Return :
'Authors : Bart Schelkens
'Reviews :
'Date Creation: 13/08/2002
'Modifications:
' nr : date : reason
'Errorhandling:
'Remarks : A connection to the database and a data adapter are initialized
'-------------------------------------------------------------------------------
Public Sub New()
Try
'strCONNECTION is the connectionstring for your database
' in my case it looks like this => "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Development\MyDatabase.mdb"
mconDB = New OleDbConnection(strCONNECTION)
mconDB.Open()
mdtaDataAdapter = New OleDbDataAdapter()
Catch e As Exception
Throw (e)
End Try
End Sub
And then i use this to fill my dataset :
'-------------------------------------------------------------------------------
'Usage : Fetches a typed Artists dataset list of rows
'Parameters : -
'Return :
' A typed Artists Dataset
'Authors : Bart Schelkens
'Reviews :
'Date Creation: 13/08/2002
'Modifications:
' nr : date : reason
'Errorhandling:
'Remarks :
'-------------------------------------------------------------------------------
Public Function GetList() As DiscoBar.DataSets.DSArtists
Return FillDataSet("SELECT * FROM Artists ORDER BY Artist")
End Function
'-------------------------------------------------------------------------------
'Usage : Fetches a typed Artists dataset
'Parameters :
' ByVal vstrCommandText as string => The source sql statement used to fetch the dataset
'Return :
' A typed Artists dataset
'Authors : Bart Schelkens
'Reviews :
'Date Creation: 13/08/2002
'Modifications:
' nr : date : reason
'Errorhandling:
'Remarks :
'-------------------------------------------------------------------------------
Private Function FillDataSet(ByVal vstrCommandText As String) As DiscoBar.DataSets.DSArtists
Dim dsData As DiscoBar.DataSets.DSArtists = New DiscoBar.DataSets.DSArtists()
Dim cmdCommand As OleDbCommand = New OleDbCommand()
cmdCommand.Connection = mconDB
cmdCommand.CommandType = CommandType.Text
cmdCommand.CommandText = vstrCommandText
mdtaDataAdapter.SelectCommand = cmdCommand
mdtaDataAdapter.Fill(dsData, "Artists")
Return dsData
End Function
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.