reading empty Rows from Excel ( *.xlsx ) - c#

While I am reading from excel using this code:
OpenFileDialog ofd= new OpenFileDialog();
ofd.Title = "Select file";
ofd.Filter = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*";
ofd.FilterIndex = 1;
ofd.RestoreDirectory = true;
if (ofImport.ShowDialog() == DialogResult.OK)
{
string path = System.IO.Path.GetFullPath(ofImport.FileName);
string query = "SELECT * FROM [Sheet6$]";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofd.FileName + ";Extended Properties=" + "\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
var ds= new DataSet();
adapter.Fill(ds);
DataTable data = dsz.Tables[0];
datagridview1.DataSource = data
// to get row count
int rowCount = dg_Un_TIA.Rows.Count;
// Get the no. of columns in the first row.
int colCount = dg_Un_TIA.Rows[0].Cells.Count;
And after the code compiled i see that the rowCount = 1048574 and colCount = 17, but in the file the rows filled with data = 9000 and columns = 14
How to read those only and what the changes will be in the code
because I got out of memory Exception ...

I strongly suspect that this has something to do with the XLSX file being used. The following code, which is based on your sample with a couple of changes to which variables were being looked at, provides the expected results with a newly created Excel document:
using System;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Windows.Forms;
namespace TestApplication
{
class Program
{
[STAThread]
static void Main(string[] args)
{
OpenFileDialog ofd = new OpenFileDialog
{
Title = "Select file",
Filter = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*",
FilterIndex = 1,
RestoreDirectory = true
};
if (ofd.ShowDialog() == DialogResult.OK)
{
string query = "SELECT * FROM [Sheet1$]";
OleDbConnection conn = new OleDbConnection
{
ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofd.FileName +
";Extended Properties=" + "\"Excel 12.0 Xml;HDR=YES;IMEX=1\""
};
OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
var ds = new DataSet();
adapter.Fill(ds);
DataTable data = ds.Tables[0];
var message = string.Format("Row Count: {0}{1}Column Count: {2}", data.Rows.Count, Environment.NewLine, data.Rows[0].ItemArray.Count());
MessageBox.Show(message);
}
}
}
}
With an empty document the above code will crash but does return a row count of 0.

Related

Error: There is no row at position 0 while uploading a excel file to database

ufExcelFile.EnableViewState = false;
//filePath = ufExcelFile.Value.ToString();
filePath = Server.MapPath("~/");
filePath = filePath + ufExcelFile.Value;
Stopwatch sw = new Stopwatch();
sw.Start();
string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0;";
using (OleDbConnection excel_con = new OleDbConnection(excelConnectionString))
{
excel_con.Open();
string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString(); /****error line*****/
System.Data.DataTable dtExcel = new System.Data.DataTable();
dtExcel.Columns.AddRange(new DataColumn[3] { new DataColumn("CNIC", typeof(string)), new DataColumn("PhoneNumber", typeof(string)), new DataColumn("BatchNumber", typeof(string)) });
using (OleDbDataAdapter oda = new OleDbDataAdapter("select * from [" + sheet1 + "]", excel_con))
{
oda.Fill(dtExcel);
}
excel_con.Close();
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
//Set the database table name
sqlBulkCopy.DestinationTableName = "dbo.ExcelToDB";
//[OPTIONAL]: Map the Excel columns with that of the database table
sqlBulkCopy.ColumnMappings.Add("CNIC", "CNIC");
sqlBulkCopy.ColumnMappings.Add("PhoneNumber", "PhoneNumber");
sqlBulkCopy.ColumnMappings.Add("BatchNumber", "BatchNumber");
con.Open();
sqlBulkCopy.BulkCopyTimeout = 2700;
sqlBulkCopy.WriteToServer(dtExcel);
con.Close();
count++;
}
}
}
sw.Stop();
lblTotalExecutionTime.Visible = true;
lblTotalExecutionTime.Text = "Total Execution Time: " + sw.Elapsed;
can any one tell why is not having any sheet or any row at position zero. thanks
in advance.when i put file path in windows explorer it get file not present error too.
i have tried same code in windows application its working fine but in my website it not working with the same excel file.

how to Upload a excel file to sql database table using c# windows form application

I want to upload a excel file through windows form application in c# and want to import the data to database ( Mysql server). how can i do that??? I have created a form which requires me to upload a excel file into the mysql database . its an bulk insert data to database table.
My Excel File Contain columns like userid,password,first_name,last_name,user_group AND
MySql Database table(aster_users) Contain many columns like userid,password,first_name,last_name,user_group,queue,active,created_date,created_by,role ..
i need to upload that excel file to my database and other columns will get empty or null that's not a matter.
My Form design is
Here is My c# Code:
using MySql.Data.MySqlClient;
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace UploadFileToDatabase
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String MyConString = "SERVER=******;" +
"DATABASE=dbs;" +
"UID=root;" +
"PASSWORD=pwsd;" + "Convert Zero Datetime = True";
private void BtnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Text files | *.csv";
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName;
fileName = dlg.FileName;
txtfilepath.Text = fileName;
}
}
private void btnUpload_Click(object sender, EventArgs e)
{
string connectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtfileparth.Text + ";Extended Properties=\"Excel 12.0;HDR=YES;\"";
using (OleDbConnection connection =
new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand
("Select * FROM [Sheet1$]", connection);
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
string sqlConnectionString = MyConString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.ColumnMappings.Add("[userid]", "userid");
bulkCopy.ColumnMappings.Add("password", "password");
bulkCopy.ColumnMappings.Add("first_name", "first_name");
bulkCopy.ColumnMappings.Add("last_name", "last_name");
bulkCopy.ColumnMappings.Add("user_group", "user_group");
bulkCopy.DestinationTableName = "aster_users";
bulkCopy.WriteToServer(dr);
MessageBox.Show("Upload Successfull!");
}
}
}
}
Here is how i tried.i got an error message like this
Additional information: External table is not in the expected format.
in this line connection.Open(); . How can this be Done?
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace IMPORT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String MyConString = "SERVER=******;" +
"DATABASE=db;" +
"UID=root;" +
"PASSWORD=pws;";
private void btnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog1 = new OpenFileDialog();
openfiledialog1.ShowDialog();
openfiledialog1.Filter = "allfiles|*.xls";
txtfilepath.Text = openfiledialog1.FileName;
}
private void btnUpload_Click(object sender, EventArgs e)
{
string path = txtfilepath.Text;
string ConnString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties = Excel 8.0";
DataTable Data = new DataTable();
using (OleDbConnection conn =new OleDbConnection(ConnString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(#"SELECT * FROM [dataGridView1_Data$]", conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(Data);
conn.Close();
}
string ConnStr = MyConString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(ConnStr))
{
bulkCopy.DestinationTableName = "TABLE NAME";
bulkCopy.ColumnMappings.Add("userid", "userid");
bulkCopy.ColumnMappings.Add("password", "password");
bulkCopy.ColumnMappings.Add("first_name", "first_name");
bulkCopy.ColumnMappings.Add("last_name", "last_name");
bulkCopy.ColumnMappings.Add("user_group", "user_group");
bulkCopy.WriteToServer(Data);
MessageBox.Show("UPLOAD SUCCESSFULLY");
}
}
}
An example found http://technico.qnownow.com/bulk-copy-data-from-excel-to-destination-db-using-sql-bulk-copy/.
And
ERROR: Additional information: External table is not in the expected format
ஆர்த்தி,
Use the Below Connection String Format
string File = sResponsedExcelFilePath;
string result = Path.GetFileName(sFilePath);
ExcelReaderConnString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + File +"\\"+ result + ";Extended Properties=Excel 12.0;");
Hope this works for you.
There is an awesome link that shows how to upload to c# datatable from excel...in case the link dies I am sharing the procedure....
The excel Connection Strings for diff versions:
private string Excel03ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'";
private string Excel07ConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES'";
The File select event:
private void BtnSelectFile_Click(object sender, EventArgs e)
{
DataTable dt;
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Excel files | *.xls";
if (dlg.ShowDialog() == DialogResult.OK)
{
string filePath = dlg.FileName;
string extension = Path.GetExtension(filePath);
string conStr, sheetName;
conStr = string.Empty;
switch (extension)
{
case ".xls": //Excel 97-03
conStr = string.Format(Excel03ConString, filePath);
break;
case ".xlsx": //Excel 07 to later
conStr = string.Format(Excel07ConString, filePath);
break;
}
//Read Data from the Sheet.
using (OleDbConnection con = new OleDbConnection(conStr))
{
using (OleDbCommand cmd = new OleDbCommand())
{
using (OleDbDataAdapter oda = new OleDbDataAdapter())
{
dt = new DataTable();
cmd.CommandText = "SELECT * From [Sheet1$]";
cmd.Connection = con;
con.Open();
oda.SelectCommand = cmd;
oda.Fill(dt);
con.Close();
}
}
}
//Save the datatable to Database
string sqlConnectionString = MyConString;
if(dt != null)
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.ColumnMappings.Add("[userid]", "userid");
bulkCopy.ColumnMappings.Add("password", "password");
bulkCopy.ColumnMappings.Add("first_name", "first_name");
bulkCopy.ColumnMappings.Add("last_name", "last_name");
bulkCopy.ColumnMappings.Add("user_group", "user_group");
bulkCopy.DestinationTableName = "aster_users";
bulkCopy.WriteToServer(dt);
MessageBox.Show("Upload Successfull!");
}
}
}
}
Then you can just save the datatable to mySql database which I hope you know how to do...If you can't then comment I'll try my best to help you. Thank You
Hope this helps....
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace IMPORT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String MyConString = "SERVER=******;" +
"DATABASE=db;" +
"UID=root;" +
"PASSWORD=pws;";
private void btnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog1 = new OpenFileDialog();
openfiledialog1.ShowDialog();
openfiledialog1.Filter = "allfiles|*.xls";
txtfilepath.Text = openfiledialog1.FileName;
}
private void btnUpload_Click(object sender, EventArgs e)
{
string path = txtfilepath.Text;
string ConnString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties = Excel 8.0";
DataTable Data = new DataTable();
using (OleDbConnection conn =new OleDbConnection(ConnString))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(#"SELECT * FROM [dataGridView1_Data$]", conn);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(Data);
conn.Close();
}
string ConnStr = MyConString;
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(ConnStr))
{
bulkCopy.DestinationTableName = "TABLE NAME";
bulkCopy.ColumnMappings.Add("userid", "userid");
bulkCopy.ColumnMappings.Add("password", "password");
bulkCopy.ColumnMappings.Add("first_name", "first_name");
bulkCopy.ColumnMappings.Add("last_name", "last_name");
bulkCopy.ColumnMappings.Add("user_group", "user_group");
bulkCopy.WriteToServer(Data);
MessageBox.Show("UPLOAD SUCCESSFULLY");
}
}
}
I had huge problems trying to use either/both Jet and ACE.OLEDB providers. You could try this o/s library ClosedXML, which will import xlsx files: 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
Available via Nuget. It has its own wiki: https://github.com/ClosedXML/ClosedXML/wiki

read excel data line by line with c# .net

Does anyone know how can I read an excel file line by line in c#.
I found this code which will return the data from excel and display a grindview in c#. However, I just was wandering how to possibly read the data line by line on the server side instead?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.IO;
namespace site
{
public partial class pgTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnImport_Click(object sender, EventArgs e)
{
string connString = "";
string strFileType = Path.GetExtension(fileuploadExcel.FileName).ToLower();
string path = fileuploadExcel.PostedFile.FileName;
//Connection String to Excel Workbook
if (strFileType.Trim() == ".xls")
{
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
string query = "SELECT [username],[age],[phone] FROM [Sheet1$]";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
grvExcelData.DataSource = ds.Tables[0];
grvExcelData.DataBind();
da.Dispose();
conn.Close();
conn.Dispose();
}
}
}
Since Excel works with ranges you should first get the range of cells you would want to read. After that you can now browse through them using a for loop. You can see an example below:
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(#"C:\myexcel.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
MessageBox.Show(xlRange.Cells[i, j].Value2.ToString());
}
}
A more detailed explanation on this code block can be found here.
you can use OleDbDataReader as below
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
var val1= reader[0].ToString();
}
reader.Close();
}
You must try this
string connectionString = "";
string strFileType = "Type";
string path = #"C:\Users\UserName\Downloads\";
string filename = "filename.xls";
if (fielname.Contains(.xls))
{
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + filename + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (fielname.Contains(.xlsx)
{
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + filename + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
string query = "SELECT * FROM [SheetName$]";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(query, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
var lines = new List<string>();
while (reader.Read())
{
var fieldCount = reader.FieldCount;
var fieldIncrementor = 1;
var fields = new List<string>();
while (fieldCount >= fieldIncrementor)
{
fields.Add(reader[fieldIncrementor - 1].ToString());
fieldIncrementor++;
}
lines.Add(string.Join("\t", fields));
}
reader.Close();
}
I tried the solution with OleDbConnection but it didn't work because I didn't have something installed. Then I found this solution here and it worked like a charm:
https://www.codeproject.com/Tips/801032/Csharp-How-To-Read-xlsx-Excel-File-With-Lines-of
There you can download a small file Excel.dll, add it to your project and browse the excel files cell by cell.
A simple way to convert data table to enumerable of an object is using Json methods.
Per example, with simple method, using only dotnet libraries, you can convert data table to list of especific objects.
using System.Data;
private static IEnumerable<T> ConvertDataTable<T>(DataTable dataTable)
{
if (dataTable is null ||
!dataTable.AsEnumerable().Any())
{
return Enumerable.Empty<T>();
}
var data = dataTable.Rows.OfType<DataRow>()
.Select(row => dataTable.Columns.OfType<DataColumn>()
.ToDictionary(col => col.ColumnName, c => row[c]));
var jsonTextObject = System.Text.Json.JsonSerializer.Serialize(data);
return System.Text.Json.JsonSerializer.Deserialize<IEnumerable<T>>(jsonTextObject)
?? Enumerable.Empty<T>();
}

Importing Any Excel Spreadsheet into a DataGridView - C#

I have a program that imports an excel spreadsheet into a datagridview. I have written the code as follows:
try
{
OleDbConnectionStringBuilder connStringBuilder = new OleDbConnectionStringBuilder();
connStringBuilder.DataSource = file;
connStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
connStringBuilder.Add("Extended Properties", "Excel 8.0;HDR=NO;IMEX1");
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT * FROM [All Carpets to Excel$]";
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connStringBuilder.ConnectionString;
selectCommand.Connection = connection;
adapter.SelectCommand = selectCommand;
data = new DataSet();
adapter.Fill(data);
dataGridView1.DataSource = data.Tables[0].DefaultView;
}
catch (IOException)
{
}
The line "selectCommand.CommandText = "SELECT * FROM [All Carpets to Excel$]";" takes the data from the sheet with that name. I was wondering how I could get this program to open an excel document with any sheet name. One that I may not know.
You can get all the sheets' names like so..
public string[] GetExcelSheetNames(string excelFileName)
{
OleDbConnection con = null;
DataTable dt = null;
String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFileName + ";Extended Properties=Excel 8.0;";
con= new OleDbConnection(conStr);
con.Open();
dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
String[] excelSheetNames = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow row in dt.Rows)
{
excelSheetNames[i] = row["TABLE_NAME"].ToString();
i++;
}
return excelSheetNames;
}

Using OleDB to read excel file in c#?

I am building a program to read excel file into dataGridView.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace pro1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string sConnecStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\\Copy_of_Acute_HCV_2008.xls" + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conObj = new OleDbConnection(sConnecStr);
conObj.Open();
OleDbCommand sqlCommand = new OleDbCommand("SELECT * FROM [Sheet1$]",conObj);
OleDbDataAdapter adaObj = new OleDbDataAdapter();
adaObj.SelectCommand = sqlCommand;
DataSet setObj = new DataSet();
adaObj.Fill(setObj);
conObj.Close();
dataGridView1.DataSource = setObj.Tables[0];
dataGridView1.Refresh();
}
}
}
The program runs fine when i use a small excel file but when i use a big excel file it gives me this error
An unhandled exception of type
'System.Data.OleDb.OleDbException'
occurred in System.Data.dll
Additional information: 'Sheet1$' is
not a valid name. Make sure that it
does not include invalid characters or
punctuation and that it is not too
long.
thanks
edit: i always use .xls files not .xlsx
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
if ((txtFilePath.HasFile))
{
OleDbConnection conn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
string query = null;
string connString = "";
string strFileName = DateTime.Now.ToString("ddMMyyyy_HHmmss");
string strFileType = System.IO.Path.GetExtension(txtFilePath.FileName).ToString().ToLower();
if (strFileType == ".xls" || strFileType == ".xlsx")
{
txtFilePath.SaveAs(Server.MapPath("~/UploadedExcel/" + strFileName + strFileType));
}
string strNewPath = Server.MapPath("~/UploadedExcel/" + strFileName + strFileType);
if (strFileType.Trim() == ".xls")
{
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed) conn.Open();
string SpreadSheetName = "";
DataTable ExcelSheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
SpreadSheetName = ExcelSheets.Rows[0]["TABLE_NAME"].ToString();
query = "SELECT * FROM [" + SpreadSheetName + "]";
cmd = new OleDbCommand(query, conn);
da = new OleDbDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "tab1");
}
}
}

Categories

Resources