help! ado connection string variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • link
    New Member
    • Nov 2006
    • 71

    help! ado connection string variable

    hi everyone,

    please help me on how to put my data path in variable. I'm using ADO and my database is visual foxpro 6 and I'm using visual basic 6.

    this is my connection string:
    Provider=VFPOLE DB.1;Data Source=D:\2007\ 01\18;Mode=Read ;Password="";Co llating Sequence=GENERA L

    my recordsource is:
    t_tran.dbf

    it worked properly if i put my connection string in ado properties but when putting it in a variable it won't work anymore.

    the t_tran.dbf is placed in different folder on every each day. which means, if today is jan, 18, 2007 then the directory would be c:\2007\01\18\t _tran.dbf and tomorrow, the data path will change because the date will be c:\2007\01\19.

    So my option in opening the database is to select the date, then the path will change to the specific date.

    Hope I explained it correctly.

    Thanks in advance :)
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Can you show us the existing code? Replacing a hard-coded literal with a variable sounds simple, but there's always something that we weren't aware of.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by link
      ...
      this is my connection string:
      Provider=VFPOLE DB.1;Data Source=D:\2007\ 01\18;Mode=Read ;Password="";Co llating Sequence=GENERA L
      ...
      I'll take a quick stab at it. Sorry if this is not what you're after, but I'm using a lot of guess-work here. :)
      Code:
      Dim strConn As String
      strConn = "Provider=VFPOLEDB.1;Data Source=D:\" _
        & format(Year(Now()) _
        & "\" _
        & Format(Month(Now(),"00") _
        & "\" _
        & Format(Day(Now(),"00") _
        & ";Mode=Read;Password="""";Collating Sequence=GENERAL"

      Comment

      • link
        New Member
        • Nov 2006
        • 71

        #4
        Originally posted by Killer42
        I'll take a quick stab at it. Sorry if this is not what you're after, but I'm using a lot of guess-work here. :)
        Code:
        Dim strConn As String
        strConn = "Provider=VFPOLEDB.1;Data Source=D:\" _
          & format(Year(Now()) _
          & "\" _
          & Format(Month(Now(),"00") _
          & "\" _
          & Format(Day(Now(),"00") _
          & ";Mode=Read;Password="""";Collating Sequence=GENERAL"
        thanks Killer42,

        here is my code...

        Dim rs As New ADODB.Recordset
        Dim cn As New ADODB.Connectio n

        Private Sub Form_Load()

        cn.Open ("Provider=VFPO LEDB.1;Data Source=D:\;Mode =Read;Password= "";Collatin g Sequence=MACHIN E")
        rs.Open "select * from t_tran", cn

        End Sub

        I'm using ADO and datagrid, it works when i'm only using their properties but can't make it in coding.

        I want to view the data using datagrid and put the data source as variable...exam ple as

        xdata = "d:\"
        Data Source=xdata

        then view the content of the database using datagrid...is this possible sir?

        thanks

        Comment

        Working...