How to set the connection string of a DataSourc at run time?

  • Thread starter Thread starter GB
  • Start date Start date
G

GB

Hi,

My DataSource (MS Access database set of tables) location is in fact
determined at run time by the user. I use a default location at design time.
How can I modify the connection to the default datasource to setup its path
and name according to run time locations?

And also :
How do I modify, at run time, the dataset (or DataAdapter or whatever) to :
- filter (restrict to given selected rows) (WHERE Clause)
- order the rows (ORDER BY Clause)

I will appreciate a link to any sample code which illustrates these issues.

Thanks

GB
 
My DataSource (MS Access database set of tables) location is in fact
determined at run time by the user. I use a default location at design
time. How can I modify the connection to the default datasource to setup
its path and name according to run time locations?

Have you considered letting the user browse to it?
 
GB,

What version are you using? (2002/2003 or 2005)

However, you can forever set the connectionstring to the connection just
before opening it.

Conn.connectionstring = .................................

Cor
 
To continue in Cor's vein, what I do is:
'Get user input to database in variable sDBPath

Dim MDB_CONNECT_STRING AS STRING= _
... any parameters you need & _
"Jet OLEDB:Data Source=" & sDBPath
CreateConnectDB = New OleDbConnection(MDB_CONNECT_STRING)

I need variable WHERE clauses when I get the user to specify certain
criteria for filtering. I'll usually have a button that says "Apply Filter"
after they made the specifications. In the "Apply Filter" button clicked
event I'll have the code to see what fields I need to filter on:

'Values for sPFLead and sPFLead are assigned as part of text/combo
box validation
sProjFilter = ""

If Me.ckbCancProjects.Checked = False Then sProjFilter =
"(Gating_Status <> 'Cancelled')"

If Len(Trim(sPFPgm)) > 0 Then
If Len(Trim(sProjFilter)) > 0 Then sProjFilter = sProjFilter & "
AND "
sProjFilter = "(Program = '" & sPFPgm & "')"
End If

If Len(Trim(sPFLead)) > 0 Then
If Len(Trim(sProjFilter)) > 0 Then sProjFilter = sProjFilter & "
AND "
sProjFilter = sProjFilter & "(NSS_Lead = '" & sPFLead & "')"
End If
'... additional tests for other variables. sProjFilter is built up
along the way

'Finally
dvProjects.RowFilter = sProjFilter
 
Back
Top