database connection module

wilko18

Member
Joined
Feb 7, 2006
Messages
11
Programming Experience
Beginner
This module works fine the first time it is used. The data in the dataset is used to populate a list view. On clicking an item in the listview, a new sql query is generated...and I was hoping to simply call this module to get the new data into a dataset, just as in the first instance.

However when it gets down to "oledbDataAdapter1.fill(dataset1) it throws an error

"unhandled exception of type 'System.Data.OleDb.OleDbException' occurred"

Any ideas why it works the first time its used and not the second?

Public Sub connection()
'create dataset to retrive data
Dim dataset1 As New DataSet
dataset1 =
New DataSet("dataset1")
dataset1.Clear()
'assign connection string
Dim ConnectionString As String = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=""C:\Documents and Setting" & _
"s\user\Desktop\WIS copy.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global " & _
"Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database" & _
"=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Da" & _
"tabase Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Loc" & _
"ale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admi" & _
"n;Jet OLEDB:Encrypt Database=False"
Dim Connection1 As OleDbConnection = New OleDbConnection(ConnectionString)
'assigns query to command
Dim command1 As OleDbCommand = New OleDbCommand(query)
command1.CommandType = CommandType.Text
'open connection
Try
If Connection1.State = ConnectionState.Closed Then
Connection1.Open()
End If
Catch ex As Exception
Throw ex
End Try
'assign connection to command
command1.Connection = Connection1
'create data adapter and assign command text
Dim oledbDataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
oledbDataAdapter1.SelectCommand = command1
'fill dataset1 with retrieved data
Try
oledbDataAdapter1.Fill(dataset1)
Catch ex As Exception
Throw ex
End Try
'pass data to global dataset 'ds' to be picked up in form
dsStations = dataset1
'close and dispose connection
Connection1.Close()
oledbDataAdapter1.Dispose()
dataset1.Dispose()
command1.Dispose()
End Sub




Thanks
 
Back
Top