本人不是很熟悉数据库,我把一切代码移植到控制台就不能用了。
有那位大侠给我一些简单的数据库操作代码好吗??[email protected]
有那位大侠给我一些简单的数据库操作代码好吗??[email protected]
解决方案 »
- MFC非模式对话框关闭后的消息处理
- 关于lParam转换成CString类型,急求!
- WTL 多线程
- 我想做一个MFC ActiveX控件 该控件就像一个应用程序一样 但是。。。
- 运行时错误:“试图越过其尾端对一未命名文件进行读写。”,不知道是原因导致的啊?!
- 怎么vc.net没有了ClassWizard??还有WizardBar也不见了?
- CString类的函数Format有哪些意思,谁能给我解释一下,我没有找到相关的介绍,vc的函数太多了
- 谁有Gif文件格式的资料或谁愿意用 Java编写合并两个Gif文件为一个Gif文件的程序,价格可商量???急!!!
- supperlxf(嘿嘿) 在吗,还是求助!!!
- 如何关闭modem声音
- 急,有关ActiveX弹出对放框的问题
- 程序添加文件后,编译出错,帮忙看看
"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;
}写EXCEL的一段代码,基于mfc的