還沒有真正解決過這個問題。但它更易於閱讀上使用的OleDbConnection這樣的Excel文件無論是:
try
{
using (OleDbConnection olcon = new OleDbConnection())
{
olcon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(fileupFile.FileName) + ";Extended Properties=Excel 12.0";
OleDbCommand olcmd = new OleDbCommand("SELECT * FROM [Sheet1$]", olcon);
olcon.Open();
OleDbDataReader olread = olcmd.ExecuteReader();
while (olread.Read())
{
line = (String)(olread.GetString(0));
Verify(line); //calls the datatosql method
}
olcon.Close();
lblFiup.Text = "Data Inserted Sucessfully";
lblFiup.ForeColor = System.Drawing.Color.Green;
}
}
然後,進入另一種方法,它使用的SqlConnection寫入到SQL Server。像這樣:
protected void datatosql(String url, String stat)
{
try
{
using (SqlConnection sqlcon = new SqlConnection("Server=(local);Database=URLs;Trusted_Connection=True"))
{
using (SqlCommand sqlcom = sqlcon.CreateCommand())
{
sqlcom.CommandText = "INSERT INTO WEVRecordsTest (URL, Status) VALUES ('" + url + "','" + stat + "')";
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
}
}
catch (SqlException se)
{
lblHist.Text = se.Message;
lblHist.ForeColor = System.Drawing.Color.Red;
}
}
需要更多的細節。開發環境?網絡服務器?爲什麼通常的保存路徑不起作用?不知道爲什麼你想要得到一個涉及這個SQL Server。 – Bill 2010-08-13 18:42:08
我得到的savePath是@「C:\ desktop \」,顯然是因爲我在本地盒子上託管了web應用程序,所以無法找到文件路徑。至於涉及SQL,我認爲我將能夠將文件保存到SQL,以便它能夠找到它......這是否有意義? **對不起,我覺得以前的評論會誤導人們相信我真的不需要幫助..當我真的這樣做。嘿嘿。 – loreedee 2010-08-16 20:59:13