如果要將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中了。