1樓:蹇永芬壬辰
必須安裝mysql的驅動才行,不管是vb還是c++都需要這個驅動。
**如下:
public
function
exemysql(byval
sqlas
string)
asadodb.recordset
sql=
trim$(sql)
setconn
=new
adodb.connection
setrs
=new
adodb.recordset
conn.open
"driver=mysql
odbc
3.51
driver;"&_
"server=伺服器地址;"&_
"port=3306;"&_
"database=資料庫名;"&_
"uid=使用者名稱;"&_
"pwd=密碼"
conn.defaultdatabase
="資料庫名"
conn.cursorlocation
=aduseclient
setrs.activeconnection=conn
rs.locktype
=adlockbatchoptimisticrs.cursortype
=adopenkeyset
rs.open
sqlset
exesql=rs
setrs
=nothing
setconn
=nothing
endfunction
2樓:
rss回報型別不匹配:也就是說插入的資料中型別有與欄位的資料型別不一致,自己檢查下
3樓:匿名使用者
沒用mysql 我用盜版的sql:)
vb怎麼連線資料庫寫入資料?
4樓:51cto學院
'在使用前需要先安裝mysql的驅動,進行正確配置
'注意:必須給出正確的伺服器名、資料庫名、表名、資料庫連線的使用者名稱、密碼
option explicit
dim cnn as adodb.connection '定義ado連線物件
dim records as adodb.recordset '定義ado記錄集物件
'連線到資料庫
function cnnopen(byval servername as string, byval dbname as string, byval tblname as string, byval user as string, byval pwd as string) '伺服器名或ip、資料庫名、登入使用者、密碼
dim cnnstr as string '定義連線字串
set cnn = createobject("adodb.connection") '建立ado連線物件
cnn.commandtimeout = 15 '設定超時時間
cnnstr = "driver=;server=" & servername & ";database=" & dbname & ";u;pwd=" & pwd & ";stmt=set names gbk" '
cnn.connectionstring = cnnstr
cnn.open
end function
'關閉連線
function cnnclose()
if cnn.state = 1 then
cnn.close
end if
end function
'把excel寫入mysql中的資料庫
function inserttomysql(byval sheetname as string, byval tblname as string)
dim sqlstr as string
dim i, j as integer
dim columns, rows as integer
columns = vbaproject.func_public.gettotalcolumns(sheetname)
rows = vbaproject.func_public.gettotalrows(sheetname)
set records = createobject("adodb.recordset")
'取得結果集並插入資料到資料庫
set records = createobject("adodb.recordset")
'以下語句提供了插入思路,我只是把單條記錄的插入方式改為迴圈,以把所有的記錄新增到表中
'rs.open "insert into newtable values('" & activesheet.cells(i, 1).
value & "'," & "'" & activesheet.cells(i, 2).value & "')", cnn, 0
for i = 2 to rows
sqlstr = "insert into " & tblname & " values('" & sheets(sheetname).cells(i, 1).value & "'" '注意:
" values('",字母「v」之前是有空格的!!!
for j = 2 to columns
sqlstr = sqlstr & ",'" & sheets(sheetname).cells(i, j).value & "'"
next
sqlstr = sqlstr & ")"
set records = cnn.execute(sqlstr) 'rs.open sqlstr, cnn, 0 不能用這條語句實現!!!
next
msgbox "insert!", vbokonly, "excel to mysql"
end function
'清除物件
function clearobj()
set cnn = nothing
set records = nothing
end function
5樓:匿名使用者
option explicit
dim hwd as long '存放窗體控制代碼dim pid as long '存放程序iddim hprocess as long '存放程序控制代碼dim h as long '存放二級指標dim buffer as long '存放一級指標dim hp as integer '存放血量dim mp as integer '存放魔法值dim jy as integer '存放經驗值dim maxmp as integer '存放魔法上限dim maxhp as integer '存放血量上限dim dj as integer '人物等級private sub form_load()hwd = findwindow(vbnullstring, "element client") '讀取hwnd
if hwd = 0 then
msgbox "遊戲未執行!!!!!", , "遊戲未執行"
end if
getwindowthreadprocessid hwd, pid '獲取程序識別符號
hprocess = openprocess(process_all_access, 0, pid) '將程序識別符號做為引數,返回目標程序pid的控制代碼,得到此控制代碼後即可對目標進行讀寫操,process_all_access表示完全控制,許可權最大
if hprocess = 0 then
msgbox "不能開啟程序!!!!!", , "開啟程序錯誤"
exit sub
end if
VB高手進 急啊
private sub currentsub dim a 10 as string nextsub a end sub private sub nextsub byval b as string 你想按地址傳遞的話用byref 處理陣列b end sub 這樣設計有利於模組的獨立性。定義一個全域性變...
VB高手請進,VB高手請進
1.19 2.03.58 4.x mod 2 0 and x mod 5 0 或 x mod 10 0 5.12345.68 6.堆疊 7.bas 8.34 9.910.15 40.dim a as double dim i as integer a 60.0 i 0do until a 70.0 ...
vb高手進!幫忙寫出程式過程啊
private sub command1 click dim m,f,t m 100000 30 t 0.01 dot t 2 f f t n n 1 loop while n 30 msgbox 陌生人給富翁 m 元錢 msgbox 富翁給陌生人 f 元錢 end sub sub money di...