VB讀寫Ini文件及訪問MySQL數(shù)據(jù)庫的示例_第1頁
VB讀寫Ini文件及訪問MySQL數(shù)據(jù)庫的示例_第2頁
VB讀寫Ini文件及訪問MySQL數(shù)據(jù)庫的示例_第3頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、本文格式為word版,下載可任意編輯vb讀寫ini文件及訪問mysql數(shù)據(jù)庫的示例 loadsettings()和savesettings()是讀寫ini文件的例子,留意要先把ini文件名賦值給inifile這個(gè)變量。getsqlval()函數(shù)從指定的mysql服務(wù)器的指定表中通過指定的sql抓取一個(gè)數(shù)值。 vb讀寫ini文件,及訪問mysql數(shù)據(jù)庫的示例。 attribute vb_name = module3option explicitpublic declare function getprivateprofilestring lib kernel32 alias getprivate

2、profilestringa (byval lpapplicationname as string, byval lpkeyname as any, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as longpublic declare function getprivateprofileint lib kernel32 alias getprivateprofileinta (byval lpapplicationna

3、me as string, byval lpkeyname as string, byval ndefault as long, byval lpfilename as string) as longpublic declare function writeprivateprofilestring lib kernel32 alias writeprivateprofilestringa (byval lpapplicationname as string, byval lpkeyname as any, byval lpstring as any, byval lpfilename as s

4、tring) as longtype appsettingl16netenabled(3) as booleanl16nethost(3) as stringl16netport(3) as integerchabointerval as integerend typetype mysql_settinghost as stringport as integerusername as stringpassword as stringdbname as stringsql as stringenabled as booleanend typepublic inifile as stringpub

5、lic appset as appsettingpublic mysqlset(3) as mysql_settingpublic function inireadstring(byval appname as string, byval keyname as string, byval default as string, byval filename as string) as stringdim retstr as stringretstr = string(10000, 0)inireadstring = left(retstr, getprivateprofilestring(app

6、name, byval keyname, default, retstr, len(retstr), filename)end functionsub loadsettings()dim i as integerfor i = 1 to ubound(appset.l16nethost) + 1with appset.l16nethost(i - 1) = inireadstring(main, l16nethost i, 192.168.0.100, inifile).l16netport(i - 1) = getprivateprofileint(main, l16netport i, 1

7、881, inifile).l16netenabled(i - 1) = cbool(inireadstring(main, l16netenabled i, 0, inifile) 將“true、“false的字符串轉(zhuǎn)成boolean值end withnext iappset.chabointerval = getprivateprofileint(main, chabointerval, 10, inifile)for i = 1 to ubound(mysqlset) + 1with mysqlset(i - 1).host = inireadstring(mysql, host i,

8、192.168.0.100, inifile).port = getprivateprofileint(mysql, port i, 3306, inifile).username = inireadstring(mysql, username i, root, inifile).dbname = inireadstring(mysql, dbname i, , inifile).password = inireadstring(mysql, password i, , inifile).sql = inireadstring(mysql, sql i, , inifile).enabled

9、= cbool(inireadstring(mysql, enabled i, false, inifile)end withnext iend subsub savesettings()dim i as integerdim v as integerfor i = 1 to ubound(appset.l16nethost) + 1with appset loadsettings()和savesettings()是讀寫ini文件的例子,留意要先把ini文件名賦值給inifile這個(gè)變量。getsqlval()函數(shù)從指定的mysql服務(wù)器的指定表中通過指定的sql抓取一個(gè)數(shù)值。 writepr

10、ivateprofilestring main, l16nethost i, .l16nethost(i - 1), inifile writeprivateprofilestring main, l16netport i, cstr(.l16netport(i - 1), inifilewriteprivateprofilestring main, l16netenabled i, cstr(.l16netenabled(i - 1), inifile 寫入的是“true、“falseend withnext iwriteprivateprofilestring main, chaboint

11、erval, cstr(appset.chabointerval), inifilefor i = 1 to ubound(mysqlset) + 1with mysqlset(i - 1)writeprivateprofilestring mysql, host i, .host, inifilewriteprivateprofilestring mysql, port i, cstr(.port), inifilewriteprivateprofilestring mysql, username i, .username, inifilewriteprivateprofilestring

12、mysql, password i, .password, inifilewriteprivateprofilestring mysql, dbname i, .dbname, inifilewriteprivateprofilestring mysql, sql i, .sql, inifilewriteprivateprofilestring mysql, enabled i, cstr(.enabled), inifileend withnext iend subfunction getsqlval(idx as integer) as integerdim con as adodb.c

13、onnectiondim rds as adodb.recordsetdim strconnect as stringstrconnect = driver=mysql odbc 5.1 driver; _uid= mysqlset(idx).username ;pwd= mysqlset(idx).password ; _server= mysqlset(idx).host ;port= mysqlset(idx).port ; _database= mysqlset(idx).dbname ;set con = new adodb.connectionuse a client-side c

14、ursorcon.cursorlocation = aduseclienton error goto err_1con.open strconnectset rds = new adodb.recordsetthe only type of curor that you can use witha client side cursor location is adopenstatic.rds.cursortype = adopenstaticrds.cursorlocation = aduseclientthis guarantees that a record that is being e

15、ditedcan be saved.rds.locktype = adlockpessimistica sql statement indicating which data to get from the database.rds.source = mysqlset(idx).sqlrds.activeconnection = conopen the record set. opening the recordset willcause the movecomplete event for the recordset to fire.rds.openif the pointer is at the end of the recordset ofat the before

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論