Method 1: import data to a DataSet object. Only the standard format of Excel is supported, that is, cells cannot be merged.
/// /// Import data to the dataset/// Note: This method only supports the original excel File/// /// /// /
Method 1: import data to a DataSet object. Only the standard format of Excel is supported, that is, cells cannot be merged.
/// /// Import data to the dataset/// Note: This method only supports the original excel File/// /// /// /
source connectionTry{If (excelConn. State = ConnectionState. Closed){ExcelConn. Open ();}}Catch (Exception ex){MessageBox. Show ("An error occurred while connecting to the data source! "," Error ",MessageBoxButtons. OK, MessageBoxIcon. Error );Application. Exit ();}Finally{If (excelConn. State = ConnectionState. Open)ExcelConn. Close ();}
// Set the query commandOleDbDataAdapter myCommand = new OleDbDataAdapter ("SELECT * FROM [Sheet1 $]", excelConn
executed once and every round-trip with the database server. If the data volume is large, the system performance is also a challenge.
2. import data in Excel-use the writetoserver method of sqlbulkcopy to import data in batches
The disadvantage of this approach is that the E
Authentication3. data exchange is also beneficial.
Implementation Method:Sqlconnection conn = new sqlconnection (system. configuration. configurationsettings. deleettings ["conn"]);Sqldataadapter da = new sqldataadapter ("select * From tb1", Conn );Dataset DS = new dataset ();Da. Fill (DS, "Table1 ");Datatable dt = Ds. Tables ["Table1"];Stringwriter Sw = new str
. Identity Authentication3. data exchange is also beneficial.
Implementation Method:Sqlconnection conn = new sqlconnection (system. configuration. configurationsettings. deleettings ["conn"]);Sqldataadapter da = new sqldataadapter ("select * From tb1", Conn );Dataset DS = new dataset ();Da. Fill (DS, "Table1 ");Datatable dt = Ds. Tables ["Table1"];Stringwriter S
If you import data to SqlServer in Excel, the system prompts: too many fields are defined? Source code: fileName file name savePath path DataSetdsnull; try {stringmyStringProviderMicrosoft. Jet. OLEDB.4.0; DataSource + savePath + fileName +; ExtendedPropertiesExcel
If you import data to SqlServer in Excel, the system p
The connection string of Excel2007 is different from that of Excel2003.
DataTable tbSheetName = connection. GetOleDbSchemaTable (OleDbSchemaGuid. Tables, null );Used to obtain the sheet name.
using System;using System.IO;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.OleDb; namespace ExcelDataReader{ public class ExcelDataReader { private static string BuildConnectionString(string filepath) { if (!File.Exist
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.