|
-
Jan 24th, 2005, 09:25 AM
#1
Thread Starter
Hyperactive Member
<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:
Private Sub Combo1_Click()
SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
SQL = SQL & "From [EmployeesData], [Contacts]"
SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
Adodc1.RecordSource = SQL ' Execute your query
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).
-
Jan 24th, 2005, 03:19 PM
#2
Fanatic Member
Re: <help>Populate DATAGRID using ADODB
Similar to what you already have...
VB Code:
Dim cn as new adodb.connection
Dim rs as new adodb.recordset
cn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<Path of your database.mdb>;"
rs.open SQL, cn, adOpenKeyset, adLockOptimistic, adCmdText
if rs.eof = false then
Set DataGrid1.DataSource = rs
else
msgbox "No records"
end if
Here's to us!
Who's like us?
Darned few, and they're all dead!
-
Jan 25th, 2005, 10:46 AM
#3
Thread Starter
Hyperactive Member
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).
-
Jan 25th, 2005, 10:52 AM
#4
Fanatic Member
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!
-
Jan 25th, 2005, 01:35 PM
#5
Thread Starter
Hyperactive Member
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).
-
Jan 25th, 2005, 02:29 PM
#6
Fanatic Member
Re: <help>Populate DATAGRID using ADODB
Try adding this:
VB Code:
rs.CursorLocation = adUseClient
Before the rs.Open line.
Here's to us!
Who's like us?
Darned few, and they're all dead!
-
Jan 25th, 2005, 03:42 PM
#7
Thread Starter
Hyperactive Member
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:
Private Sub Combo1_Click()
If RS.State = adStateOpen Then RS.Close
SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
SQL = SQL & "From [EmployeesData], [Contacts]"
SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
RS.Open SQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText
'RS.Requery
'Adodc1.RecordSource = SQL ' Execute your query
'Set DataGrid1.DataSource = Adodc1 ' Bind to the data control
'\\\\\\\\\\\\\\\\\\\\
If RS.EOF = False Then
RS.CursorLocation = adUseClient
Set DataGrid1.DataSource = RS
Else
MsgBox "No records"
End If
End Sub
Habibalby
Current Project: General Employees Database (Employees Information) & (Training Details).
-
Jan 25th, 2005, 04:53 PM
#8
Fanatic Member
Re: <help>Populate DATAGRID using ADODB
You had the cursor location in the wrong spot. Try this:
VB Code:
Private Sub Combo1_Click()
If RS.State = adStateOpen Then RS.Close
SQL = "Select EmployeesData.[FirstName], EmployeesData.[SecondName], Contacts.[Mobile]"
SQL = SQL & "From [EmployeesData], [Contacts]"
SQL = SQL & "Where EmployeesData.[EmpID] = Contacts.[EmpID]"
SQL = SQL & "And EmployeesData.[FirstName]='" & Combo1.Text & "';"
RS.CursorLocation = adUseClient
RS.Open SQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText
'RS.Requery
'Adodc1.RecordSource = SQL ' Execute your query
'Set DataGrid1.DataSource = Adodc1 ' Bind to the data control
'\\\\\\\\\\\\\\\\\\\\
If RS.EOF = False Then
Set DataGrid1.DataSource = RS
Else
MsgBox "No records"
End If
End Sub
Here's to us!
Who's like us?
Darned few, and they're all dead!
-
Jan 26th, 2005, 05:35 AM
#9
Thread Starter
Hyperactive Member
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).
-
Jan 26th, 2005, 12:34 PM
#10
Fanatic Member
Re: <help>Populate DATAGRID using ADODB [SOLVED]
Something like the following:
VB Code:
For i = 0 To LeadsGrid.Columns.count - 1
If LeadsGrid.Columns(i).DataField = "ProjJobNum" Then
LeadsGrid.Columns(i).Width = Len(LeadsGrid.Columns(i)) + 1000
LeadsGrid.Columns(i).Caption = "Job Number"
End If
'do the same with other columns...
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!
-
Jan 26th, 2005, 04:02 PM
#11
Thread Starter
Hyperactive Member
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).
-
Jan 26th, 2005, 04:55 PM
#12
Fanatic Member
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!
-
Jan 27th, 2005, 03:19 AM
#13
Thread Starter
Hyperactive Member
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).
-
Jun 7th, 2005, 02:30 PM
#14
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|