 |
 |

12-31-2002, 05:24 PM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
DataGrid exhaustion
|
I give up! This has driven me nuts for 2 days. I know it's something simple but my mind is worn out.
I simply want to populate the datagrid with data using code (only).
What am I missing?
Thanks
-------------
Option Explicit
Public cnT As ADODB.Connection
Public rsT As ADODB.Recordset
Public mSQLT As String
Private Sub Form_Load()
Set cnT = New ADODB.Connection
cnT.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LEDCO\Bourne-Access.mdb;Persist Security Info=False"
mSQLT = "Select distinct manufacturer from TLMFG order by manufacturer asc"
Set rsT = New ADODB.Recordset
rsT.Open mSQLT, cnT, adOpenStatic, adLockOptimistic, adCmdText
Set DataGrid1.DataSource = rsT
DataGrid1.Caption = "MANUFACTURERS LIST"
'??????? what now ?
End Sub
|
Last edited by JohnB92882; 12-31-2002 at 05:56 PM.
|

12-31-2002, 05:56 PM
|
|
Senior Contributor
Retired Moderator * Guru *
|
|
Join Date: Aug 1999
Location: Hartford, Connecticut, 06
Posts: 1,487
|
|
|
I want to ask you, too: ?????? what now?
That is easier this way:
1- assign the cnt.connectionString = "BlaBla ..."
2- cnt.Open
3- assign rst.ActiveConnection = cnt
4- rst.Open
Then run the code in Debug mode to see what is going on.
|
|

01-01-2003, 07:31 PM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
Datagrid out - MSHFlexgrid in
|
I've decided the datagrid is a waste of time and opt for the MSHFG. No problem now - it works just like it should.
|
|

01-02-2003, 05:58 AM
|
|
|
datagrid probs
I have had the same probs with the grid and found out this:
*They are always working if you use thim with datacontrols ADODC and a db on the same machine. But not always over a network.
*They are sometimes working in standard exes with connection-strings. but sometims just not...
*They are often working if you use them in an OCX
just to tell you that you are not allone 
|
|

01-02-2003, 07:27 AM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
dbg vs MSHFG & MSFG - dbg is a dag
|
Thanks for the reply - I did an ado with the datagrid over and over again and I could not get it to populate - I was even tempted to reinstall Visual Studio. For sake of my mind I tried the MSHFG and it instantly did what it should using virtually the same code.
It seems odd but who can spend the time researching for the answer. I tried - I have a good library and swear by O'Reiley's books, especially "Visual Basic Controls In A Nutshell". Nothing worked with the dbg. I even went to several (at least 15) forums and still the same thing. That's when I put up an MSHFG, an MSFG, and the dbg, side by side. The MSH and the MSF both did the right thing but no mater how many variations on the dbg it was just blank.
From the amount of forum inquiries on this subject it appears the dbg is a problem control for many programmers.
I'd love to see more opinions to this problem - perhaps someone has the answer.
|
|

01-02-2003, 09:35 AM
|
|
Freshman
|
|
Join Date: Dec 2002
Location: Toronto
Posts: 46
|
|
|
Before opening the recordset, try:
rsT.CursorLocation = adUseClient
I've had the same problem and found that the DBGrid needs a client side cursor.
|
|

01-02-2003, 10:18 AM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
datagrid vs mshflexgrid, listbox & combobox
|
N/G on the cursor -
I went back to my test form - it has a selection combobox, a list box that lists what's selected in the mshflexgrid, an MSHFlexgrid that lists all items filtered to the combobox, and (now) a datagrid. The code is simple and works except for the datagrid.
This code should also give others an idea of how to use 1 control to display or filter another control. Not included are my rs and cn closing procedures.
However - the datagrid issue still remains
-----------------
Option Explicit
Public cn As ADODB.Connection
Public rs6 As ADODB.Recordset
Public rs7 As ADODB.Recordset
Public mSQL6 As String
Public mSQL7 As String
Public mMfg As String
--------------------
' This works for a MSHFlexGrid
Private Sub dcbMfg_Click(Area As Integer)
MSHFlexGrid1.ClearStructure
mMfg = dcbMfg.Text
mSQL7 = "Select * from TLMFG where Manufacturer like '" & mMfg & "' order by Manufacturer asc"
Set rs7 = New ADODB.Recordset
rs7.Open mSQL7, cn, adOpenStatic, adLockOptimistic, adCmdText
Set MSHFlexGrid1.Recordset = rs7
MSHFlexGrid1.Refresh
End Sub
---------------------------
' This adds the MSHFG selections to a listbox
Private Sub MSHFlexGrid1_Click()
List1.AddItem (MSHFlexGrid1.Text)
End Sub
------------------------
'Here's the main code for all controls
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LEDCO\Bourne-Access.mdb;Persist Security Info=False"
mSQL6 = "Select distinct Manufacturer from TLMFG"
Set rs6 = New ADODB.Recordset
rs6.Open mSQL6, cn, adOpenStatic, adLockOptimistic, adCmdText
Set dcbMfg.RowSource = rs6
dcbMfg.ListField = "manufacturer"
dcbMfg.Text = "Eagle"
mSQL7 = "Select distinct manufacturer from TLMFG order by manufacturer asc"
Set rs7 = New ADODB.Recordset
rs7.Open mSQL7, cn, adOpenStatic, adLockOptimistic, adCmdText
MSHFlexGrid1.ColWidth(1) = 1500
MSHFlexGrid1.ColWidth(2) = 2500
DataGrid1.Caption = "Test Grid"
Set DataGrid1.DataSource = rs7
DataGrid1.Refresh
' rs7.CursorLocation = adUseClient
End Sub
The last few lines above do not populate the datagrid - I'd really like to know how to manage the datagrid - I still think it's a dog.
John
|
Last edited by JohnB92882; 01-02-2003 at 10:42 AM.
|

01-02-2003, 12:21 PM
|
|
Freshman
|
|
Join Date: Dec 2002
Location: Toronto
Posts: 46
|
|
|
According to the code above, you did not put the adUseClient in the right place. Place it BEFORE the following line:
rs7.CursorLocation = adUseClient
rs7.Open mSQL7, cn, adOpenStatic, adLockOptimistic, adCmdText
You cannot change the Cursor type once the recordset is opened.
|
|

01-02-2003, 12:25 PM
|
|
|
OK, here is the way that always work when using a ADODC.
If you want I can also send you code tomorow from my job where I managed it to work in your way with connection-strings.
This is how to do it with the ADODC:
============================
Open a new Visual Basic project and add a reference to the "Microsoft ActiveX Data Objects Library."
Add the "Microsoft ADO Data Control" and the "Microsoft DataGrid control" to the project's component list.
Add a DataGrid (DataGrid1) and an ADO Data Control (ADODC1) to the default Visual Basic form (Form1).
Set the ConnectionString property of the ADO Data Control (ADODC1) to the following (make sure to modify the path to reflect the location for your location:
Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data
Source=C:\temp\test.mdb
Set the CommandType property of the ADO Data Control (ADODC1) to:
2 - adCmdTable
Set the RecordSource property of the ADO Data Control (ADODC1) to:
theNameOfTheTable
Set the DataSource property of the Microsoft DataGrid Control (DataGrid1) to:
ADODC1
Mail me if you want the other code or try to look at my homepage.
YEs... it is in Swedish  but maybe you understand something anyway...
best regards
www.ivarssons.nu/petter
petter@ivarssons.nu
|
|

01-02-2003, 03:37 PM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
|
The objective is to use code to populate a datagrid with code - not an adodc object. An adodc design time object works fine with a datagrid but hard code requires something else.
Perhaps the client side cursor as suggested above (I will work on that tonight and let you all know).
Thanks
John
|
|

01-03-2003, 07:43 AM
|
|
|
Tested your code
I have now tested your code. it worked fine in an ActiveX control (OCX) but not in a standard exe.
maybe there is something notable with the way i used the cab. here is the way I did:
----------------------------------------------
*I created a new ActiveX Control
*Made ocx...
*Created Package with PD-wizard
*Published the package on my webbserver
*Opened the cab and the inf-file from the server
*Copied the CLASSID into the HTML-page
*Loaded the connection-string from HTML with VBScript via an method in the ocx that I called CheckInInit() like this:
----------------------------------------------
<object name="objCheckIn"
classid="CLSID:AF4FDC7D-F489-4375-9C73-AACAF1261EA7"
codebase="CheckIn.CAB#version=1,2,0,2" id="UserControl1" style="LEFT: 0px; TOP: 0px">
</object>
<script language="vbscript">
Call objCheckIn.CheckInInit(myConnectString)
</script>
I do not mean that you have to put in an webpage.
i just wanted to show you that I tested the code.
But why it did not worked out in an standard exe...
i do not know and it is irritating
Hope this was some help
//Petter
|
Last edited by petterivarsson; 01-03-2003 at 08:02 AM.
|

01-03-2003, 08:45 AM
|
|
Regular
|
|
Join Date: Nov 2002
Location: Riverside, CA
Posts: 57
|
|
|
Yes - I think the datagrid has limitations. I opt for the MSHFlexgrid (more features). I'd like to thank you for your input. Quite often we evaluate 1 problem and learn many new things in the process - and meet interesting people too.
Thanks again
John
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|