udl 連mysql 幾種常見的資料庫連線方法

2021-10-13 12:11:17 字數 2051 閱讀 7619

連線access資料庫

1. 使用已有dsn的連線字串進行連線(odbc)

使用dsn進行連線

//匯入命名空間usingsystem.data.odbc;protectedvoidpage_load(object sender,eventargs e)

ctionstring屬性為provider(提供程式名),data source(excel文家愛女實際路徑名),extended properties(附加屬性)。其中,extended properties制定一些附加的屬性,如excel的版本(本例為excel 8.0)和hdr值。hdr=yes表示**的第一行為標題,應用程式使用sql語句查詢時不會選擇第一行的內容;hdr=no則表示應用程式會把**中所選的全部內容(包括第一行)查詢出來。

訪問txt檔案

1.使用odbc.net data provider

使用odbc.net data provider

stringconnstr=@"driver=microsoft text driver(*.txt;*.csv);dbq=c:\samplepath\;extensions=asc,csv,tab,txt;";

odbcconnection myconnection=newodbcconnection(connstr);

odbccommand mycommand=newodbccommand("select * from txtsample.txt",myconnection);

2.使用ole db.net data provider

使用oledb.net data provider

stringconnstr=@"provider=microsoft.jet.oledb.4.0;data source=c:\samplepath\;extended properties=**text;hdr=yes;fmt=delimited""";

oledbconnection myconnection=newoledbconnection(connstr);

oledbcommand mycommand=newoledbcommand("select * from txtsample.txt",myconnection);

3.使用system.io命名空間

system.io命名空間包含的主要類:

file:提供用於建立、複製、刪除、移動和開啟檔案的靜態方法(即不需要建立類的例項,可直接呼叫類的方法)。

fileinfo:提供建立、複製、刪除、移動和開啟檔案的例項方法(即需要建立類的例項,才能呼叫類的方法)。

streamreader:從資料流中讀取字元。

streamwriter:從資料流中寫入字元。

file類包含的主要方法

opentext:開啟現有的txt檔案以進行讀取。

exists:確定制定的檔案是否存在。

createtext:建立或開啟乙個檔案用於寫入。

讀取txt檔案

response.write("

");//建立streamreader類的物件streamreader objstreamreader;stringfilecont;//開啟現有的txt檔案並將其賦值給streamreader物件objstreamreader=file.opentext(@"c:\txtsample.txt");//迴圈呼叫readline方法讀取txt文字,直至讀完,並將結果顯示在窗體中while(objstreamreader.peek()!=-1)

filecont=objstreamreader.readline();

response.write(filecont+"

");}//讀取完成,關閉streamreader類的物件objstreamreader.close();

寫入txt檔案

response.write("

");//定義新建txt文字的路徑stringfile_name=@"c:\sample.txt";//如果txt檔案已存在,報錯;否則,執行寫操作if(!file.exists(file_name))

else{

response.write("已經存在此檔案!");

mysql 常見的幾種日誌設定

mysql日誌是我們需要掌握的知識,下面就為您介紹幾個最常見的mysql日誌型別,如果您對mysql日誌方面感興趣的話,不妨一看。1 錯誤日誌 記錄啟動 執行或停止mysqld時出現的問題。my.ini配置資訊 enter a name for the error log file.otherwis...

mysql中常見的幾種索引

主鍵索引 資料列不允許重複,不允許為null,乙個表只能有乙個主鍵。唯一索引 資料列不允許重複,允許為null值,乙個表允許多個列建立唯一索引。可以通過 alter table table name add unique column 建立唯一索引 可以通過 alter table table na...

mysql 幾十連線 mysql的幾種連線方式

下面是例子分析 表a記錄如下 aid anum 1 a20050111 2 a20050112 3 a20050113 4 a20050114 5 a20050115 表b記錄如下 bid bname 1 2006032401 2 2006032402 3 2006032403 4 20060324...