用VB的向导很容易实现,原来可以用ADO的Data Shaping Service。对ADO又多了一些了解。在VC++6.0中,我想用ADODC和DATAGRID控件实现 C_Recordset recordset;recordset=m_adodc1.GetRecordset();m_datagrid.SetRefDataSource((LPUNKNOWN)childrecordset); 问题是怎样得到childrecordset(类似VB代码adoPrimaryRS("ChildCMD").UnderlyingValue)。 ************ Private Sub Form_Load() Dim db As Connection Set db = New Connection db.CursorLocation = adUseClient db.Open "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;dsn=publishers;uid=sa;pwd=;" Set adoPrimaryRS = New Recordset adoPrimaryRS.Open "SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_salenotes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD", db, adOpenStatic, adLockOptimistic Dim oText As TextBox 'Bind the text boxes to the data provider For Each oText In Me.txtFields Set oText.DataSource = adoPrimaryRS Next Set grdDataGrid.DataSource = adoPrimaryRS("ChildCMD").UnderlyingValue mbDataChanged = False End Sub
用VB的向导很容易实现,原来可以用ADO的Data Shaping Service。对ADO又多了一些了解。在VC++6.0中,我想用ADODC和DATAGRID控件实现。ADODC的连接串为Provider=MSDataShape.1;Persist Security Info=False;Location=Localhost;Data Source=publishers;User ID=sa;Initial Catalog=pubs;Data Provider=MSDASQL SQL为SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_sales,notes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD 相关代码如下: C_Recordset recordset;
recordset=m_adodc1.GetRecordset();
m_datagrid.SetRefDataSource((LPUNKNOWN)childrecordset); 问题是怎样得到childrecordset(类似VB代码adoPrimaryRS( "ChildCMD ").UnderlyingValue)。 ************ Private Sub Form_Load() Dim db As Connection Set db = New Connection db.CursorLocation = adUseClient db.Open "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;dsn=publishers;uid=sa;pwd=; "
Set adoPrimaryRS = New Recordset adoPrimaryRS.Open "SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_salenotes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD ", db, adOpenStatic, adLockOptimistic
Dim oText As TextBox 'Bind the text boxes to the data provider For Each oText In Me.txtFields Set oText.DataSource = adoPrimaryRS Next
Set grdDataGrid.DataSource = adoPrimaryRS( "ChildCMD ").UnderlyingValue
C_Recordset recordset;recordset=m_adodc1.GetRecordset();m_datagrid.SetRefDataSource((LPUNKNOWN)childrecordset);
问题是怎样得到childrecordset(类似VB代码adoPrimaryRS("ChildCMD").UnderlyingValue)。
************
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;dsn=publishers;uid=sa;pwd=;" Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_salenotes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD", db, adOpenStatic, adLockOptimistic Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next Set grdDataGrid.DataSource = adoPrimaryRS("ChildCMD").UnderlyingValue mbDataChanged = False
End Sub
SQL为SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_sales,notes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD
相关代码如下:
C_Recordset recordset;
recordset=m_adodc1.GetRecordset();
m_datagrid.SetRefDataSource((LPUNKNOWN)childrecordset); 问题是怎样得到childrecordset(类似VB代码adoPrimaryRS( "ChildCMD ").UnderlyingValue)。
************
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDataShape;Data PROVIDER=MSDASQL;dsn=publishers;uid=sa;pwd=; "
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "SHAPE {select pub_id,pub_name,city,state,country from publishers} AS ParentCMD APPEND ({select title_id,title,type,pub_id,price,advance,royalty,ytd_salenotes,pubdate from titles } AS ChildCMD RELATE pub_id TO pub_id) AS ChildCMD ", db, adOpenStatic, adLockOptimistic
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next
Set grdDataGrid.DataSource = adoPrimaryRS( "ChildCMD ").UnderlyingValue
mbDataChanged = False
End Sub