It's not who you are underneath, it's what you do that defines you

C# Winform中读取EXcel

如果要将Excel的中的数据导入SqlServer中,那么,先要将excel中的数据,读入到内存中的数据表中,然后,遍历表数据,插入数据库

this.lb_status.Visible = false;
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
DataSet ds=new DataSet ();
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fd.FileName + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
strExcel = string.Format("select * from [{0}$]", "Bicycle"); //Bicycle为excel中工作薄
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, "Bicycle");
}

这段代码,可以将excle中的数据,导入到dataset中,接下来如何处理,自己看着办了,数据都在dataset中了。

 

 

http://www.cnblogs.com/chen-fan/articles/1985168.html

posted @ 2012-06-08 16:29  金铭杰  阅读(4806)  评论(0编辑  收藏  举报

Brick walls are there for a reason :they let us prove how badly we want things