Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to bind Adodc to datagrid at run time

Status
Not open for further replies.

MALICKA

Programmer
Oct 16, 2002
46
HK
I have problem in binding the adodc to datagrid

With adodc1
.ConnectionString = Conn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.RecordSource = rs
.Refresh
End With
I can;t set the record set
error in .RecordSource = rs //compile error
any example on adodc & datagrid would be a great help
 
Best way of finding out about ADODC properties is to use properties 'wizard'

Right click on the ADODC control in design mode and select ADODC properties. That will bring up a tabbed dialog box. As you work through the tabs all the answers get set up.

Then if you want to do it yourself next time (eg use a SQL statement generated on the fly) you can copy connection string and/or datasource and modify them in code as needed.

Finally set the Datasource of the Grid to ADODC1 Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks
I have done like that first set the table & coonection at design time & then modify at run time i get error
I get all the record in the datagrid ( query given in design time).
But i can't set the record at run time

I have pasted that code here hope you can understand where i commit mistake

Private Sub ShowDetail()
Dim rs As New ADODB.Recordset
Set rs = do2.CreateRecordSet("SELECT DND_SEQ_NO, DND_REF, DND_SP_NO, DND_SP_DES, DND_QTY, DND_U_PRC FROM TXDLNDTF WHERE DND_DLN_NO = '" & txtfield(0) & "' ORDER BY DND_SEQ_NO")

createrecordset // module to create recordset

//ADODC1.RecordSource = rs ( type mismatch error)

ADODC1.RecordSource = "SELECT DND_SEQ_NO, DND_REF, DND_SP_NO, DND_SP_DES, DND_QTY, DND_U_PRC FROM TXDLNDTF WHERE DND_DLN_NO = '" & txtfield(0) & "' ORDER BY DND_SEQ_NO"

ADODC1.Refresh // run time error methos refrsh of object
adodc not set
Set DataGrid1.DataSource = ADODC1
GridColumnSize
GridColumnName
GridColumnFormat
rs.Close
End Sub
 
Set your ADODC CommandType to adCommandText then set ADODC recordsource to your SQL string. The ADODC opens the recordset for you - you don't need CreateRecordset line at all. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I tried before it failed
Query i give in recordsource is

"SELECT DND_SEQ_NO, DND_REF, DND_SP_NO, DND_SP_DES, DND_QTY, DND_U_PRC FROM TXDLNDTF WHERE DND_DLN_NO = '" & txtfield(0) & "' ORDER BY DND_SEQ_NO"

but i get runtime error incorrect syntax near &

txtfield(0) has the quotation number based on quotaion number
details selected from adodc
 
sorry it sould be without quotes
Even then it does not return any record set
as txtfield(0) value is generated at run time
 
How do you mean <as txtfield(0) value is generated at run time> and <txtfield(0) has the quotation number based on quotaion number details selected from adodc>?

It sounds as if your query is using results from your query!

What am I missing? Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Sorry i mislead
form contain header & detail
Quotaion number ( field is in) both header & detail
i need to select the
quotaion detail where quotaion header = quotaion detail
Both header & detail recordset is fetched from the class module

Set rs = do2.CreateRecordSet(&quot;SELECT DND_SEQ_NO, DND_REF, DND_SP_NO, DND_SP_DES, DND_QTY, DND_U_PRC FROM TXDLNDTF WHERE DND_DLN_NO = '&quot; & txtfield(0) & &quot;' ORDER BY DND_SEQ_NO&quot;)

do2 = detail class module
it sould be like
adodc1.recordsource = rs ( the record set obtained from detail class module)
but i get error
so i just tried with the same query

What i need is to get the detail in to adodc & then bind to datagrid
 
As I said before an ADODC recordsource will be a SQL statement not a recordset.

Just set your ADODC recordsource to:
&quot;SELECT DND_SEQ_NO, DND_REF, DND_SP_NO, DND_SP_DES, DND_QTY, DND_U_PRC FROM TXDLNDTF WHERE DND_DLN_NO = '&quot; & txtfield(0) & &quot;' ORDER BY DND_SEQ_NO&quot;
then do your refresh and rebind the datagrid. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Huh still problem
I did't get any error on setting recordsource but no data is diplayed on the datagrid

datagrid1.rebind //gives error 4097 can't initilaize databinding

datagrid1.datasource = adodc1 returns no error

MsgBox Adodc1.Recordset.RecordCount //returns 0 so no record is fetched from recordsource
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top