


Implementation method of importing Excel into SQL database using C programming language
How to import excel into sql database using code in C
///
/// Read data from Excel
///
/// Path
///
public DataSet ImportFromExcel(string filePath)
{
DataSet ds = new DataSet();
string connString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " filePath ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""";
DataTable table = OleDbHelper.GetExcelTables(connString);
if(table == null || table.Rows.Count
{
return null;
}
foreach(DataRow dr in table.Rows)
{
string cmdText = "select * from [" dr["TABLE_NAME"].ToString() "]";
DataTable dt = OleDbHelper.FillDataTable(connString, cmdText);
dt.TableName = dr["TABLE_NAME"].ToString();
ds.Tables.Add(dt);
}
return ds;
}
Next, just write the DataSet into the database
How to import excel spreadsheet into visual foxpro database
There is no better way to import excel tables into vfp, but it can be achieved by reading excel.
The following is an example of vfp directly reading an EXCEL file:
M_File=GETFILE('xls','Order File')
IF M_File=""
=MESSAGEBOX ("Please select the order receipt file to be imported!", 0 48, "Prompt")
RETURN
ELSE
IF JUSTEXT(M_FILE)#"XLS" &Get file extension
=MESSAGEBOX ("The document you selected is not an EXCEL document!", 0 48, "Prompt")
RETURN
ENDIF
ENDIF
USE Book Order Form
ZAP
myexcel=createobject('excel.application') &Create an object
myexcel.visible=.f.&invisible
bookexcel=myexcel.workbooks.open(M_File) &Open the specified file
o_SheetName=myexcel.application.ActiveSheet.Name & Get the name of the currently active worksheet
UsedRange =bookexcel.worksheets(o_SheetName).UsedRange & Returns the area that can be used in the worksheet, the properties of the UsedRange table
o_rows=UsedRange.rows.count &summary rows
o_cols=UsedRange.columns.count&summary column
IF o_rows
=MESSAGEBOX ("The number of data rows to be imported is too few, please check!", 0 16, "Prompt")
ELSE
FOR i=2 TO o_rows
m1=myexcel.cells(i,1).value &ISBN
m2=myexcel.cells(i,2).value & book title
m3=myexcel.cells(i,3).value &Publisher
m4=myexcel.cells(i,4).value &author
m5=myexcel.cells(i,5).value &pricing
m6=myexcel.cells(i,6).value & quantity
APPEND BLANK
REPLACE ISBN WITH m1, book title WITH m2, publisher WITH m3, author WITH m4, price WITH m5, quantity WITH m6
ENDFOR
ENDIF
myexcel.workbooks.close &Close workspace
myexcel.quit &Close excel
brow
The above is the detailed content of Implementation method of importing Excel into SQL database using C programming language. For more information, please follow other related articles on the PHP Chinese website!

This tutorial explains the Excel SUMIF function in plain English. The main focus is on real-life formula examples with all kinds of criteria including text, numbers, dates, wildcards, blanks and non-blanks. Microsoft Excel has a handful o

In this article, you will learn how to build an Excel IF statement for different types of values as well as how to create multiple IF statements. IF is one of the most popular and useful functions in Excel. Generally, you use an IF statem

This tutorial shows how to sum a column in Excel 2010 - 2016. Try out 5 different ways to total columns: find the sum of the selected cells on the Status bar, use AutoSum in Excel to sum all or only filtered cells, employ the SUM function

In this tutorial you will learn what a PivotTable is, find a number of examples showing how to create and use Pivot Tables in all version of Excel 365 through Excel 2007. If you are working with large data sets in Excel, Pivot Table comes

This tutorial explains the difference between the SUMIF and SUMIFS functions in terms of their syntax and usage, and provides a number of formula examples to sum values with multiple AND / OR criteria in Excel 365, 2021, 2019, 2016, 2013,

Excel wildcards: a powerful tool for efficient search and filtering This article will dive into the power of wildcards in Microsoft Excel, including their application in search, formulas, and filters, and some details to note. Wildcards allow you to perform fuzzy matching, making it more flexible to find and process data. *Wildcards: asterisks () and question marks (?)** Excel mainly uses two wildcards: asterisk (*) and question mark (?). *Asterisk (): Any number of characters** The asterisk represents any number of characters, including zero characters. For example: *OK* Match the cell containing "OK", "OK&q

The tutorial shows how to create multiple IF statements in Excel with AND as well as OR logic. Also, you will learn how to use IF together with other Excel functions. In the first part of our Excel IF tutorial, we looked at how to constru

In this tutorial, you will lean a quick way to calculate percentages in Excel, find the basic percentage formula and a few more formulas for calculating percentage increase, percent of total and more. Calculating percentage is useful in m


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use
