Control Panel
Forum
Hosting Help
6 Months free Hosting (New!)
Resources
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
80998
Average new registrations per day (in last 7 days):
41
New Registration:
Open
Register Now
Home
»
Resources
»
How to Program with EXCEL
ASP.NET
ADO.NET
Web Services
Remoting
Visual Studio 2005
Error Bank
Interview Questions
Tips & Tricks
XML
HTML
Jscript/Javascript
IIS
Windows
General
Submit Resource or code snippet
... and get
surprise gifts
Win Digital camera, ASP.NET Books, Free softwares!!
How to Program with EXCEL
19 Apr, 2008
Author:
yansoft
Summary
This show The way to Fetch data from EXCEL
.NET Classes used :
OleDbConnection Excel_Conn = new OleDbConnection();
Excel_Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=1;IMEX=1;';" + "Data Source= " + Source_path;
OleDbCommand Excel_cmd = Excel_Conn.CreateCommand();
string str_excel_sql = "SELECT * FROM [Sheet1$]";
Excel_cmd.CommandText = str_excel_sql;
OleDbDataAdapter Excel_adptor = new OleDbDataAdapter();
Excel_adptor.SelectCommand = Excel_cmd;
model_pep model = new model_pep(MyConn.Connstr,MyConn.Logstr);
DataSet Excel_ds = new DataSet();
try
{
Excel_Conn.Open();
Excel_adptor.Fill(Excel_ds, "[Sheet1$]");
Base_pep bll = new Base_pep();
int count = Excel_ds.Tables["[Sheet1$]"].Rows.Count;
this.progressBar_Main.Minimum = 0;
this.progressBar_Main.Maximum = count;
int i = 0;
foreach (DataRow row in Excel_ds.Tables["[Sheet1$]"].Rows)
{
try
{
i++;
this.progressBar_Main.Value = i;
bll.ID = row["??"].ToString().Trim();
bll.Name = row["??"].ToString().Trim();
bll.Sex = row["??"].ToString().Trim();
bll.Dep = row["??"].ToString().Trim();
if (row["????"].ToString().Length != 0)
{
bll.RegTime = Convert.ToDateTime(row["????"].ToString());
}
else
{
bll.RegTime = Convert.ToDateTime("1900-01-01");
}
if (row["????"].ToString().Length != 0)
{
bll.AgeTime = Convert.ToDateTime(row["????"].ToString());
}
else
{
bll.AgeTime = Convert.ToDateTime("1900-01-01");
}
bll.Project = row["??"].ToString().Trim();
if (row["??"].ToString().Length != 0)
{
bll.BoneAge = Convert.ToDouble(row["??"].ToString());
}
else
{
bll.BoneAge = 0.0;
}
if (row["????"].ToString().Length != 0)
{
double x = Convert.ToDouble(row["????"].ToString());
int y = (int)(x * 10);
double z = (double)(x * 10 - y);
if (z >= 0.5) y += 1;
bll.LifeTime = (double)(y / 10.0);
}
else
{
bll.LifeTime = 0.0;
}
bll.Remark = row["??"].ToString().Trim();
bll.PicPath =false;
bll.No = GetID(bll.Sex, bll.Dep, bll.Project);
model.Add(bll);
}
catch (Exception er)
{
MessageBox.Show(er.Message.TOleDbConnection Excel_Conn = new OleDbConnection();
Excel_Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=1;IMEX=1;';" + "Data Source= " + Source_path;
OleDbCommand Excel_cmd = Excel_Conn.CreateCommand();
string str_excel_sql = "SELECT * FROM [Sheet1$]";
Excel_cmd.CommandText = str_excel_sql;
OleDbDataAdapter Excel_adptor = new OleDbDataAdapter();
Excel_adptor.SelectCommand = Excel_cmd;
model_pep model = new model_pep(MyConn.Connstr,MyConn.Logstr);
DataSet Excel_ds = new DataSet();
try
{
Excel_Conn.Open();
Excel_adptor.Fill(Excel_ds, "[Sheet1$]");
Base_pep bll = new Base_pep();
int count = Excel_ds.Tables["[Sheet1$]"].Rows.Count;
this.progressBar_Main.Minimum = 0;
this.progressBar_Main.Maximum = count;
int i = 0;
foreach (DataRow row in Excel_ds.Tables["[Sheet1$]"].Rows)
{
try
{
i++;
this.progressBar_Main.Value = i;
bll.ID = row["??"].ToString().Trim();
bll.Name = row["??"].ToString().Trim();
bll.Sex = row["??"].ToString().Trim();
bll.Dep = row["??"].ToString().Trim();
if (row["????"].ToString().Length != 0)
{
bll.RegTime = Convert.ToDateTime(row["????"].ToString());
}
else
{
bll.RegTime = Convert.ToDateTime("1900-01-01");
}
if (row["????"].ToString().Length != 0)
{
bll.AgeTime = Convert.ToDateTime(row["????"].ToString());
}
else
{
bll.AgeTime = Convert.ToDateTime("1900-01-01");
}
bll.Project = row["??"].ToString().Trim();
if (row["??"].ToString().Length != 0)
{
bll.BoneAge = Convert.ToDouble(row["??"].ToString());
}
else
{
bll.BoneAge = 0.0;
}
if (row["????"].ToString().Length != 0)
{
double x = Convert.ToDouble(row["????"].ToString());
int y = (int)(x * 10);
double z = (double)(x * 10 - y);
if (z >= 0.5) y += 1;
bll.LifeTime = (double)(y / 10.0);
}
else
{
bll.LifeTime = 0.0;
}
bll.Remark = row["??"].ToString().Trim();
bll.PicPath =false;
bll.No = GetID(bll.Sex, bll.Dep, bll.Project);
model.Add(bll);
}
catch (Exception er)
{
MessageBox.Show(er.Message.ToString());
}
}
MessageBox.Show("????", "????");
i = 0;
}
catch(Exception er)
{
MessageBox.Show(er.Message.ToString());
}oString());
}
}
MessageBox.Show("????", "????");
i = 0;
}
catch(Exception er)
{
MessageBox.Show(er.Message.ToString());
}
Feedbacks about this page from members:
- No Feedbacks yet !! -
Submit Feedback
View All Feedbacks
Partners
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies.
All Rights Reserved.