Results 1 to 14 of 14

Thread: <help>Populate DATAGRID using ADODB [SOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Resolved <help>Populate DATAGRID using ADODB [SOLVED]

    Hi guys,

    I need help to populate a DataGrid usingi the ADODB 2.8 by MS-Access Table.

    Here's the code which I use for ADODC but in my case I want to use ADODB.
    VB Code:
    1. Private Sub Combo1_Click()
    2.  
    3. SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
    4. SQL = SQL & "From [EmployeesData], [Contacts]"
    5. SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
    6. SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
    7.  
    8. Adodc1.RecordSource = SQL                   ' Execute your query
    9. Set DataGrid1.DataSource = Adodc1    ' Bind to the data control


    Can anyone help please ??

    Many thanks in advance,

    habibalby
    Last edited by Habibi; Jan 26th, 2005 at 12:20 PM.
    Current Project: General Employees Database (Employees Information) & (Training Details).

  2. #2
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB

    Similar to what you already have...

    VB Code:
    1. Dim cn as new adodb.connection
    2. Dim rs as new adodb.recordset
    3.  
    4. cn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.         "Data Source=<Path of your database.mdb>;"
    6.  
    7. rs.open SQL, cn, adOpenKeyset, adLockOptimistic, adCmdText
    8.  
    9. if rs.eof = false then
    10.   Set DataGrid1.DataSource = rs
    11. else
    12.   msgbox "No records"
    13. end if
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB

    I've tried this code it doesn't do anything mate! Any further help ?
    Current Project: General Employees Database (Employees Information) & (Training Details).

  4. #4
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB

    Are you reference Microsoft ADO in your project?
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB

    Yes, becuase I've tired the Same Query using ListView and everything works fine.
    Current Project: General Employees Database (Employees Information) & (Training Details).

  6. #6
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB

    Try adding this:
    VB Code:
    1. rs.CursorLocation = adUseClient

    Before the rs.Open line.
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB

    I've tried that also same and it says Operation is not allowed when the Object is Open.
    VB Code:
    1. Private Sub Combo1_Click()
    2.  
    3. If RS.State = adStateOpen Then RS.Close
    4. SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
    5. SQL = SQL & "From [EmployeesData], [Contacts]"
    6. SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
    7. SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
    8. RS.Open SQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText
    9.  
    10. 'RS.Requery
    11. 'Adodc1.RecordSource = SQL                   ' Execute your query
    12. 'Set DataGrid1.DataSource = Adodc1    ' Bind to the data control
    13.  
    14. '\\\\\\\\\\\\\\\\\\\\
    15.  
    16. If RS.EOF = False Then
    17. RS.CursorLocation = adUseClient
    18.  
    19.   Set DataGrid1.DataSource = RS
    20. Else
    21.   MsgBox "No records"
    22. End If
    23.  
    24.  
    25. End Sub

    Habibalby
    Current Project: General Employees Database (Employees Information) & (Training Details).

  8. #8
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB

    You had the cursor location in the wrong spot. Try this:
    VB Code:
    1. Private Sub Combo1_Click()
    2.  
    3. If RS.State = adStateOpen Then RS.Close
    4. SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
    5. SQL = SQL & "From [EmployeesData], [Contacts]"
    6. SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
    7. SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
    8.  
    9. RS.CursorLocation = adUseClient
    10.  
    11. RS.Open SQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText
    12.  
    13. 'RS.Requery
    14. 'Adodc1.RecordSource = SQL                   ' Execute your query
    15. 'Set DataGrid1.DataSource = Adodc1    ' Bind to the data control
    16.  
    17. '\\\\\\\\\\\\\\\\\\\\
    18.  
    19. If RS.EOF = False Then
    20.   Set DataGrid1.DataSource = RS
    21. Else
    22.   MsgBox "No records"
    23. End If
    24.  
    25.  
    26. End Sub
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB

    Yes, it works like a charm Very Good Thank Your For you Help4, but how do I make a Caption for the Columns ?

    Thanks
    Last edited by Habibi; Jan 26th, 2005 at 04:00 PM.
    Current Project: General Employees Database (Employees Information) & (Training Details).

  10. #10
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB [SOLVED]

    Something like the following:

    VB Code:
    1. For i = 0 To LeadsGrid.Columns.count - 1
    2.   If LeadsGrid.Columns(i).DataField = "ProjJobNum" Then
    3.     LeadsGrid.Columns(i).Width = Len(LeadsGrid.Columns(i)) + 1000
    4.     LeadsGrid.Columns(i).Caption = "Job Number"
    5.   End If
    6.   'do the same with other columns...
    7. Next i

    Of course, you'll have to change the grid name and field names to suit your program. Also shows you how to change column width.
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB [SOLVED]

    It's seems this will take a big effort, leave it.

    Many Thanks for your help dude.

    Best Regards,
    Habibalby
    Current Project: General Employees Database (Employees Information) & (Training Details).

  12. #12
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: <help>Populate DATAGRID using ADODB [SOLVED]

    You could also change the field names in the query to set them as the column names.

    ie: Select EmployeesData.[FirstName] AS Name

    That would make Name your column name.
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Location
    Bahrain
    Posts
    306

    Re: <help>Populate DATAGRID using ADODB [SOLVED]

    Yes, I can do that too. I was thinking of it yesterday.

    Thanks,
    habibalby
    Current Project: General Employees Database (Employees Information) & (Training Details).

  14. #14
    Lively Member zen_master's Avatar
    Join Date
    Apr 2005
    Location
    Buffalo, NY
    Posts
    114

    Re: <help>Populate DATAGRID using ADODB [SOLVED]

    rs.open SQL, cn, adOpenKeyset, adLockOptimistic, adCmdText

    can someone explain what this is (bold)?

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