S
steve
Hi,
This is probably a stupid question but I have spent the whole day without
being able to come up with a soliution.
I want a way to give the user the choice of which database (SQL or Access)
to connect to. It's basically the same database, created with Access and
then ported to SQL server. Therefore most of the "population" code stays the
same.
I was thinking of two radio boxes or something along these lines. However i
seem to have difficulties with filing up the adapters/datasets.
The code of my latest attempt is the following:
'Global Variables
'SQL Connection String
Dim strConnectionSQL As String = "data source=Ecstlaurent23;initial
catalog=Northwind;" _
& "Integrated Security=True"
Dim SQLcn As SqlConnection = New SqlConnection(strConnectionSQL)
'Access Connection String
Dim strConnectionAccess As String = "provider=microsoft.jet.oledb.4.0;" _
& "data source=C:\RAFALE\Beta\BD\rafalebd.mdb"
Dim Accesscn As OleDbConnection = New OleDbConnection(strConnectionAccess)
.......
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim strSelect As String = "SELECT * FROM Customers"
Dim sqlAdapter As New SqlDataAdapter(strSelect, SQLcn)
Dim oleAdapter As New OleDbDataAdapter(strSelect, Accesscn)
If rdb1.Checked Then
Try
Dim SQLds As New DataSet
SQLds.Clear()
sqlAdapter.Fill(SQLds, "Customers")
cmb1.DataSource = sqlAdapter
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = sqlAdapter
cmb2.DisplayMember = "Customers.ContactName"
cmb3.DataSource = sqlAdapter
cmb3.DisplayMember = "Customers.Country"
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Dim OLEds As New DataSet
oleAdapter.Fill(OLEds, "Customers")
cmb1.DataSource = oleAdapter
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = oleAdapter
cmb2.DisplayMember = "Customers.ContactName"
cmb3.DataSource = oleAdapter
cmb3.DisplayMember = "Customers.Country"
End If
End Sub
Thanx in advance!
This is probably a stupid question but I have spent the whole day without
being able to come up with a soliution.
I want a way to give the user the choice of which database (SQL or Access)
to connect to. It's basically the same database, created with Access and
then ported to SQL server. Therefore most of the "population" code stays the
same.
I was thinking of two radio boxes or something along these lines. However i
seem to have difficulties with filing up the adapters/datasets.
The code of my latest attempt is the following:
'Global Variables
'SQL Connection String
Dim strConnectionSQL As String = "data source=Ecstlaurent23;initial
catalog=Northwind;" _
& "Integrated Security=True"
Dim SQLcn As SqlConnection = New SqlConnection(strConnectionSQL)
'Access Connection String
Dim strConnectionAccess As String = "provider=microsoft.jet.oledb.4.0;" _
& "data source=C:\RAFALE\Beta\BD\rafalebd.mdb"
Dim Accesscn As OleDbConnection = New OleDbConnection(strConnectionAccess)
.......
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim strSelect As String = "SELECT * FROM Customers"
Dim sqlAdapter As New SqlDataAdapter(strSelect, SQLcn)
Dim oleAdapter As New OleDbDataAdapter(strSelect, Accesscn)
If rdb1.Checked Then
Try
Dim SQLds As New DataSet
SQLds.Clear()
sqlAdapter.Fill(SQLds, "Customers")
cmb1.DataSource = sqlAdapter
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = sqlAdapter
cmb2.DisplayMember = "Customers.ContactName"
cmb3.DataSource = sqlAdapter
cmb3.DisplayMember = "Customers.Country"
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Dim OLEds As New DataSet
oleAdapter.Fill(OLEds, "Customers")
cmb1.DataSource = oleAdapter
cmb1.DisplayMember = "Customers.CustomerID"
cmb2.DataSource = oleAdapter
cmb2.DisplayMember = "Customers.ContactName"
cmb3.DataSource = oleAdapter
cmb3.DisplayMember = "Customers.Country"
End If
End Sub
Thanx in advance!