|
-
Sep 6th, 2000, 10:31 PM
#1
Thread Starter
Lively Member
hey can you use a datagrid control without binding it to a adodata control, i want it to display from ado obj rs. any ideas?
-
Sep 15th, 2000, 12:47 AM
#2
New Member
As far as I know the DataCombo and the DataGrid both accept only the Data Control as recordsource. I think this is a pity and I do not understand in fact why one cannot use a recordset directly. This results in multitudes of unnecessary Data controls on our forms.
Please correct me if I am wrong.
-
Sep 16th, 2000, 09:21 PM
#3
You don't have to actually put the control on the form you can make a recordset in code
Code:
Dim rs As Recordset
Set rs = New Recordset
cnnStr = Split(de.Common.ConnectionString, ";")
cnnStr(1) = "Data Source=" & fs.BuildPath(PassStr, "Common.mdb")
cnn = Join(cnnStr, ";")
SQL = "SELECT * FROM UserInfo"
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
That has some stuff to mess with the connection string but you should get the idea from that. It makes the recordset in code and you can bind it to the Datagrid
Code:
Set Datagrid1.Datasource=rs
-
Sep 18th, 2000, 01:40 AM
#4
New Member
Thank you very much Edneeis! I immediately tried your proposal. I created a new project, added Microsoft ActiveX Data Objects Library as a reference, loaded a Datagrid on the form and wrote into the Form_Load event:
>Dim myCon As ADODB.Connection
>Set myCon = New Connection
>myCon.CursorLocation = adUseClient
>strCon = "PROVIDER=SQLOLEDB.1;" _
> & "Integrated Security=SSPI;" _
> & "Persist Security Information=False;" _
> & "Initial Catalog=myDB;" _
> & "Data Source=172.16.10.4"
>myCon.Open strCon
>Dim myRst As ADODB.Recordset
>Set myRst = New ADODB.Recordset
>Dim strSQL As String
>strSQL = "SELECT * FROM myTbl WHERE ID=1"
>myRst.Open strSQL, myCon, adOpenStatic, adLockReadOnly
>Me.DataGrid1.DataSource = myRst 'ERROR happens here!!!
which, I think is equivalent to what you proposed. However I get an error "Compile error: Method or Data member not found" on the last line. I wonder whether I perhaps need an additional reference?
Besides, if I replace the Datagrid with a Datacombo and write:
>Me.DBCombo1.RowSource = myRst
it gives me "Run-time error '13': Type mismatch". I interpreted this as meaning that it refuses a recordset and wants a Data Control as RowSource. What am I doing wrong?
-
Sep 18th, 2000, 02:53 AM
#5
Simple answer any time you change the datasource of an object you have to use the Set yada yada in front
Just change the last line to
Code:
Set DBCombo1.RowSource = myRst
You can leave the Me in there if you want but its not needed
-
Sep 18th, 2000, 03:24 AM
#6
New Member
How stupid of me! You are perfectly right.
What I still do not understand is the reasoning that Microsoft applied with regard to the type of object they decided to allow as source. The DataSource of the Datagrid can be either a recordset or the data Control (as you just demonstrated), but only a Data Control and not a recordset is valid as RowSource of the DataCombo. I find it bothersome to have to have a Data Control on the form for each Combo box. Thanks.
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
|