Excel中有些数据是用文本形式保存的,这些数据库读到,有些数据用数字来保存的,这些数据读不到~~~int CDataEditerDlg::ReadExcel(int index,CARD *card)
{
int count=0; CDatabase database;
CString sSql;
CString sItem1, sItem2;
CString sDriver;
CString sDsn;
CString sFile,sPath;
//获取主程序所在路径,存在sPath中
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos); sFile = sPath + "\\card.xls"; sDriver = GetExcelDriver();
if (sDriver.IsEmpty())
{
// 没有发现Excel驱动
AfxMessageBox("没有安装Excel驱动!");
return 0;
} // 创建进行存取的字符串
sDsn.Format("ODBC;DRIVER={%s};DSN='''';DBQ=%s", sDriver, sFile); try
{
// 打开数据库(既Excel文件)
database.Open(NULL, false, false, sDsn); CRecordset recset(&database);
sSql="SELECT 点到卡号 from NewCard"; // 执行查询语句
recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
if(index!=0)
recset.Move(1000*index,SQL_FETCH_RELATIVE);
for(int i=0;i<1000;i++){
if(recset.IsEOF())
break;
recset.GetFieldValue("点到卡号", sItem1);
card->CardNO=sItem1;
card++;
count++;
recset.MoveNext();
}
database.Close();
UpdateData(FALSE);
}
catch(CDBException e)
{
// 数据库操作产生异常时...
AfxMessageBox("数据库错误: " + e.m_strError);
}
return count;
}可能是我设置的用CString sItem1来保存项的关系,但是如果用int,用文本保存那部分岂不是又读不到~~
各位有何高招
{
int count=0; CDatabase database;
CString sSql;
CString sItem1, sItem2;
CString sDriver;
CString sDsn;
CString sFile,sPath;
//获取主程序所在路径,存在sPath中
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left (nPos); sFile = sPath + "\\card.xls"; sDriver = GetExcelDriver();
if (sDriver.IsEmpty())
{
// 没有发现Excel驱动
AfxMessageBox("没有安装Excel驱动!");
return 0;
} // 创建进行存取的字符串
sDsn.Format("ODBC;DRIVER={%s};DSN='''';DBQ=%s", sDriver, sFile); try
{
// 打开数据库(既Excel文件)
database.Open(NULL, false, false, sDsn); CRecordset recset(&database);
sSql="SELECT 点到卡号 from NewCard"; // 执行查询语句
recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
if(index!=0)
recset.Move(1000*index,SQL_FETCH_RELATIVE);
for(int i=0;i<1000;i++){
if(recset.IsEOF())
break;
recset.GetFieldValue("点到卡号", sItem1);
card->CardNO=sItem1;
card++;
count++;
recset.MoveNext();
}
database.Close();
UpdateData(FALSE);
}
catch(CDBException e)
{
// 数据库操作产生异常时...
AfxMessageBox("数据库错误: " + e.m_strError);
}
return count;
}可能是我设置的用CString sItem1来保存项的关系,但是如果用int,用文本保存那部分岂不是又读不到~~
各位有何高招
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货