vc 如何逐行读取txt里的数据导入到listctrl里。给个例子。谢谢
1个回答
展开全部
_ConnectionPtr m_pConnection;
CoInitialize(NULL);//com编程用的,用于初始化com库
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydata.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
MessageBox(hwnd,"数据库连接失败,确认数据库Demo.mdb是否在当前路径下!","ggg",0);
return FALSE;
}
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open("SELECT * FROM user_Info", m_pConnection.GetInterfacePtr(), adOpenDynamic,
LockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
MessageBox(hwnd,e->ErrorMessage(),"err",0);
}
_variant_t var;
string strName,strAge;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
MessageBox(hwnd,"表内数据为空","err",0);
return 0;
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
SetWindowText(edit, " ");///
Sleep(1300);//单位毫秒
char temp[80];
var = m_pRecordset->GetCollect("user_ID");
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
strcpy( temp, strName.c_str() );
var = m_pRecordset->GetCollect("user_PWD");
if(var.vt != VT_NULL)
strAge = (LPCSTR)_bstr_t(var);
strcat(temp,strAge.c_str());
SetWindowText(edit, temp);///
/// m_AccessList.AddString( strName + " --> "+strAge );
m_pRecordset->MoveNext();
//#pragma code ("kernel32.dll")
//VOID WINAPI Sleep ( DWORD dwMilliseconds );
//#pragma code()
// 默认列表指向第一项,同时移动记录指针并显示
//m_AccessList.SetCurSel(0);
}
}
catch(_com_error *e)
{
MessageBox(hwnd,e->ErrorMessage(),"err",1);
}
CoInitialize(NULL);//com编程用的,用于初始化com库
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydata.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
MessageBox(hwnd,"数据库连接失败,确认数据库Demo.mdb是否在当前路径下!","ggg",0);
return FALSE;
}
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open("SELECT * FROM user_Info", m_pConnection.GetInterfacePtr(), adOpenDynamic,
LockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
MessageBox(hwnd,e->ErrorMessage(),"err",0);
}
_variant_t var;
string strName,strAge;
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
MessageBox(hwnd,"表内数据为空","err",0);
return 0;
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
SetWindowText(edit, " ");///
Sleep(1300);//单位毫秒
char temp[80];
var = m_pRecordset->GetCollect("user_ID");
if(var.vt != VT_NULL)
strName = (LPCSTR)_bstr_t(var);
strcpy( temp, strName.c_str() );
var = m_pRecordset->GetCollect("user_PWD");
if(var.vt != VT_NULL)
strAge = (LPCSTR)_bstr_t(var);
strcat(temp,strAge.c_str());
SetWindowText(edit, temp);///
/// m_AccessList.AddString( strName + " --> "+strAge );
m_pRecordset->MoveNext();
//#pragma code ("kernel32.dll")
//VOID WINAPI Sleep ( DWORD dwMilliseconds );
//#pragma code()
// 默认列表指向第一项,同时移动记录指针并显示
//m_AccessList.SetCurSel(0);
}
}
catch(_com_error *e)
{
MessageBox(hwnd,e->ErrorMessage(),"err",1);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询