Results 1 to 6 of 6

Thread: [RESOLVED]SQL statement in VB and databinding for FlexGrid

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Location
    MN
    Posts
    4

    [RESOLVED]SQL statement in VB and databinding for FlexGrid

    How do I use SQL statement inside VB? What's the syntex for that? I am trying to do the samething as in Access with query and then put the output data table inside a MSFlexGrid. I am using VB6, Access 2002, and MSFlexGrid 6.0.

    Am I able to do a databind with the output table from the query? If so, how?

    thank you in advance.
    Last edited by Raing; Dec 22nd, 2006 at 04:26 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Location
    MN
    Posts
    4

    Re: SQL statement in VB and databinding for FlexGrid

    DataGrid should work fine in this case too. It doesn't have to be FlexGrid. The databind should work the same for both I think.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Location
    MN
    Posts
    4

    Re: SQL statement in VB and databinding for FlexGrid

    Data1.Database.Execute "select " & TableName & "." & CheckedColumns(1) & " from " & TableName & " where " & TableName & "." & CheckedColumns(1) & " = ""04TC0052"" "

    when I run this, it gave me error message that can't excute select. Any ideas what is wrong with this?

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: SQL statement in VB and databinding for FlexGrid

    Welcome, Raing!

    You start making a connection to your database. May be that's already taken care of?
    Code:
    "select " & TableName & "." & CheckedColumns(1) & " from " & TableName & " where " & TableName & "." & CheckedColumns(1) & " = ""04TC0052"" "
    In the above code CheckedColumns(1) must be identical with the field in database with table named what TableName is. This looks to be better like: "'04TC0052'".
    Last edited by Ember; Dec 22nd, 2006 at 05:46 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Location
    MN
    Posts
    4

    Re: SQL statement in VB and databinding for FlexGrid

    The problem is solved.
    Code:
    Public Sub SearchDB()   
     Dim str As String
        str = "select " & TableName & "." & CheckedColumns(1) & " from " & TableName & " where " & TableName & "." & CheckedColumns(1) & " = ""04TC0052"" "
        'Data1.Database.CreateQueryDef "test", str
        'Data1.Database.Execute
        'Data1.Recordset = str
        Data1.RecordSource = str
        Data1.Refresh
        
    End Sub
    I used Data1.Recordset = str rather than Data1.RecordSouce.

    Thank you Ember.

    Merry Christmas!!!


    Raing

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: [RESOLVED]SQL statement in VB and databinding for FlexGrid

    Edited!
    Last edited by Ember; Dec 22nd, 2006 at 04:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width