ODBC4 - MFC

A simple CRecordView demo.

2025-12-20

Written by: xiaobin

Setting ODBC

open odbc

empty - odbc

create new data source

DSN name - data source

default DB - data source

other - data source

authenticity - data source

finish - data source

test data source

done - odbc

Note: The ODBC driver in Windows 10 21H2 can no longer connect to SQL Server 2000.

Create SDI Application

use CFormView

add CRecordSet Class

add control variable

data move

show data

After positioning the recordset, display the data for the current row:

void CMFCApplication1View::ShowRow()
{
	int nItem;
	CString tmp;

	tmp.Format(_T("%d"), m_pSet->m_qty);
	m_ListCtrl.DeleteAllItems();

	nItem = m_ListCtrl.InsertItem(0, CString(m_pSet->m_stor_id));
	m_ListCtrl.SetItemText(nItem, 1, CString(m_pSet->m_ord_num));
	m_ListCtrl.SetItemText(nItem, 2, m_pSet->m_ord_date.Format("%Y-%m-%d"));
	m_ListCtrl.SetItemText(nItem, 3, tmp);
	m_ListCtrl.SetItemText(nItem, 4, CString(m_pSet->m_payterms));
	m_ListCtrl.SetItemText(nItem, 5, CString(m_pSet->m_title_id));
}

Ref