Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MFC lesson 4 manipulating EXCEL tables using ODBC

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Option 1: make use of ready-made third-party library: CSpreadSheet

The limitation of using CSpreadSheet to operate EXCEL: you can only create a table in EXCEL, and then you can manipulate the EXCEL table in the way of ODBC, otherwise the table name after FROM in the query statement cannot be filled in.

Limit

This control needs MFC (Microsoft Foundation Class Library) support. Support for Unicode encoding was not tested. Control to read and write with ODBC

Excel file, ODBC driver is required. Excel file must be marked with columns. And the first row mark is unique (field). Prohibited

Delete the workbook, only the contents of the workbook are allowed to be deleted. The column value type refers to the program data type. Do not use Excel format.

Detailed reference: http://blog.csdn.net/andy205214/article/details/5918648

Plan 2: write and access the database by yourself

The 12345678910111213141516171819202122CDatabase db;// database library needs to contain the header file # include CString sDriver = _ T ("MICROSOFTEXCEL DRIVER (* .XLS)"); / / Excel driver CString sSql; charszRecord [6] [128] = {0}; sSql.Format (_ T ("DRIVER= {% s}; DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"% s\ "; DBQ=%s"), sDriver,strFilePath, strFilePath) If (! db.OpenEx (sSql,CDatabase::noOdbcDialog)) / / Connect data source DJB.xls {MessageBox (_ T ("failed to open EXCEL file!"), _ T ("error")); return;} / / Open EXCEL table CRecordset pset (& db); sSql.Format (_ T ("SELECTvalues1,values2 FROM Sheet1")); pset.Open (CRecordset::forwardOnly,sSql,CRecordset::readOnly); while (! pset.IsEOF ()) {pset.GetFieldValue () / / previous field pset.MoveNext ();} db.Close ()

Note:

1) obtain the corresponding attribute values in the current row through GetFieldValue

2) the sSql statement is a query statement, where Sheet1 is the table name, indicating that the table must be created in the exported file before it can be imported.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report