用OleDB讀寫Excel時,日期"字段"如何表示
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
try
{
conn.Open();
OleDbCommand olecmd=new OleDbCommand();
olecmd.Connection=conn;
olecmd.CommandText="update [Sheet$] set date='2006/02/15'";
olecmd.ExecuteNonQuery();
}
catch{}
若在excel 文件中,date 是一個日期類型的列,上面代就會有異常。提示無效的運算式法則,隻要把上面的date字段在excel中改成“文字”型的列就不會有問題,另外,在查把date 做為查詢條件時:where date='xxxx/mm/dd' 這樣寫也會報錯。sql server中這是正常的表示方法。請問上面的問題該如何表示才是正確的。也就是說更新行的某個日期類型 的字段的表方法 應該寫成 set date=? 什麼,還有在where 子句中如何寫。前提是我不能把excel文件的date列改成文字類型。