Analytics

顯示具有 OleDbDataAdapter 標籤的文章。 顯示所有文章
顯示具有 OleDbDataAdapter 標籤的文章。 顯示所有文章

2019年6月4日 星期二

[C#]如何 不安裝OracleClient使用OraOLEDB.Oracle.1連OracleDB(How to use OraOLEDB.Oracle.1 to connect DB without installing Oracle Client)


問題

如何 不安裝OracleClient使用OleDbDataAdapte provider=OraOLEDB.Oracle.1連 OracleDB r


解決方法

1.下載ODAC(for 10 g使用ODAC 11.2 Release 6 (11.2.0.4.0)版本)

2.解壓縮後開cmd=>輸入[cd 解壓縮目錄]切換路徑=>輸入如下
install.bat oledb     c:\oracle myhome true

3.系統環境變量設置=>系統=>進階系統設定=>環境變數,Path點選編輯輸入如下(設定後需要重開機)
c:\oracle;c:\oracle\bin

4.連線設定放置tnsnames.ora於C:\oracle\network\admin底下

5.程式連線設定
Provider=OraOLEDB.Oracle.1;Data Source=DBnameInTNS;User ID=test;Password=test;;Persist Security Info=False

2010年10月14日 星期四

[C#]使用 OleDbDataAdapter從Excel讀取資料再匯出EXCEL檔案(Using OleDbDataAdapter to read data from Excel files and then export EXCEL)


問題
使用 OleDbDataAdapter從Excel讀取資料再匯出EXCEL檔案



解決方法
OleDbConnection con = new OleDbConnection(DBPath);
OleDbDataAdapter da = new OleDbDataAdapter("Select * From [" + rbUploadOption.SelectedItem.Value + "$] ", con);
DataSet ds = new DataSet();
da.Fill(ds, "TEST");

GridView gvExport = new GridView();
gvExport.DataSource = ds;
gvExport.DataBind();

string ExportFilename = DateTime.Now.ToString("yyyyMMddHHmmss");
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=" + ExportFilename);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
Response.Charset = "uft8";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gvExport.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString().Replace("<div>", "").Replace("</div>", ""));
Response.End();

熱門文章