如何实现?
如果不用ODBC能否实现?
谁能给一段示例代码?谢谢了先
解决方案 »
- glDrawBuffer不起作用
- 能不能让打印机直接打印当前窗口内的所有内容?
- ATL如何创建具有窗口的ActiveX
- 在COM组件中的字符串,是使用_bstr_t还是CComBSTR?
- 请问那种运行是根据负载自动创建线程的线程池有用吗?我觉得害处比较多
- 如何用CFileDialog类得到一个文件夹的路径
- 请问大家在纯 C++中用什么函数对网页进行下载
- 紧急求助,如何在资源管理器中的目录树(tree)上增加一个节点(和控制面板同一级),节点如同“我的文档”一样,指向某个目录?
- 请大家帮我分析分析,我这样的参数转换到堤出现什么样的问题了!??:((
- CREATE_SUSPENDED掛起進程時輸入表裏的DLL已經加載完畢
- 新手请教:如何实现对话框与程序的交互?
- 如何在子框架中得到子视图的指针?谢谢。。。。
"XLS Files (*.xls)|*.xls",NULL);
CString filename;
CDatabase database;
CString sSql;
CString sItem1;
CString sDriver;
CString sDsn;
CString strSMS, sms[10000];
char cDefaultfile[MAX_PATH];
CDBVariant varValue;
int iNum, count, i;
long iIndex[10000];
char cSms[2000]; memset(cDefaultfile, 0, MAX_PATH); if (strCurrType.GetLength() == 0)
{
MessageBox("请先选择短信分组,如果没有分组,则请先建立分组","常用短信");
return;
} sDriver = theApp.GetExcelDriver();
if( sDriver.IsEmpty() )
{
AfxMessageBox("No Excel ODBC driver found");
return;
} sprintf(cDefaultfile, "%s\\temple\\常用短信\\常用短信模板.xls", theApp.GetAppPath());
filedlg.m_ofn.lpstrFile = cDefaultfile;
filedlg.m_ofn.nMaxFile = MAX_PATH;
filedlg.m_ofn.lpstrDefExt = "XLS";
if (filedlg.DoModal() == IDOK)
{
m_List.DeleteAllItems();
filename = filedlg.GetPathName();
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,filename); TRY
{
// Open the database using the former created pseudo DSN
database.Open(NULL,false,false,sDsn);
// Allocate the recordset
CRecordset recset( &database ); // Build the SQL string
// Remember to name a section of data in the Excel sheet using "Insert->Names" to be
// able to work with the data like you would with a table in a "real" database. There
// may be more than one table contained in a worksheet.
sSql = "SELECT * from [Sheet1$]";
// Execute that query (implicitly by opening the recordset)
recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly); // Browse the result
short nFields = recset.GetODBCFieldCount( ); while( !recset.IsEOF() )
{
// Read the result line
for( short index = 0; index < nFields; index++ )
{
// do something with varValu
switch (index)
{
case 0:
recset.GetFieldValue(index, sItem1);
if (sItem1.GetLength()>140)
{
MessageBox("导入的内容大于140个字节,将不允许被导入","短信导入");
recset.MoveNext();
continue;
}
iNum = theApp.GetNormalSMSNum();
iNum++;
theApp.m_db.InsertSMS(iNum, strCurrType, sItem1);
theApp.SetNormalSMSNum(iNum);
break;
default:
break;
}
}
// Skip to the next resultline
recset.MoveNext();
} // Close the database
database.Close(); count = theApp.m_db.SelSMS(iIndex, strCurrType, sms); m_List.DeleteAllItems();
for(i=0; i<count; i++)
{
sprintf(cSms, "%s", sms[i]);
InsertPhoneBook(iIndex[i], cSms);
}
}
CATCH(CDBException, e)
{
// A database exception occured. Pop out the details...
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}