vb連線mysql例項
電腦需安裝資料庫'mysql server'和'mysql connector net'相關版本軟體。
在工程的『專案』-『新增引用』中新增引用『mysql.data』
實現**如下:
imports system.io
imports system
imports system.data
imports system.windows.forms
imports mysql.data.mysqlclient
public class form1
dim conn as mysqlconnection
dim data as datatable
dim da as mysqldataadapter
dim cb as mysqlcommandbuilder
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
if not conn is nothing then conn.close()
dim connstr as string
dim reader as mysqldatareader
connstr = string.format("server=;user id=; password=; database=mysql; pooling=false", "localhost", "root", "root") '登入mysql資料庫 為本機,使用者名稱:root 密碼:root
tryconn = new mysqlconnection(connstr)
conn.open()
reader = nothing
dim cmd as new mysqlcommand("use db", conn) '進入儲存資料所用的資料庫
reader = cmd.executereader()
while (reader.read())
end while
if not reader is nothing then reader.close()
catch ex as mysqlexception
'messagebox.show(ex.tostring)
finally
if not reader is nothing then reader.close()
end try
end sub
private sub btnconn_click(byval sender as system.object, byval e as system.eventargs) handles btnconn.click
dim temp_int, int_lrow, int_rrow as integer
data = new datatable
tryda = new mysqldataadapter("select * from db_table where name='lady_gaga'", conn) '在相關表中查詢資料 db_table 為表名,name 為列名
cb = new mysqlcommandbuilder(da)
da.fill(data)
int_rrow = data.rows.count '返回查詢後的資料行數,返回0行則表示沒有找到記錄,返回大於0行,則表示找到了相關記錄
if int_rrow = 0 then
messagebox.show("無記錄")
else
messagebox.show("data.rows.item(0).item(3).tostring") 'item(0).item(3) 表示返回的第1條記錄(第一條的下標為0)中的第4列值
end if
catch ex as exception
messagebox.show(ex.tostring)
end try
end sub
end class
Python基礎 Python連線MySQL
什麼是 pymysql?pymysql 是在 python3.x 版本中用於連線 mysql 伺服器的乙個庫,python2中則使用mysqldb。pymysql 遵循 python 資料庫 api v2.0 規範,幷包含了 pure python mysql 客戶端庫。pymysql 安裝 在使用...
Windows上Python連線MySQL資料庫
python連線mysql資料庫示例 usr bin python import mysqldb conn mysqldb.connection 127.0.0.1 root root test cur conn.cursor cur.execute insert into testok id va...
phpMyAdmim和Yii 連線Mysql報錯。
之前phpmyadmim和yii連線mysql都好著的。某天,同一時候出現例如以下報錯 1 linux下phpmyadmin 出現 缺少 mysqli 擴充套件,請檢查 php 配置。2 yii 出現cdbconnection failed to open the db connection cou...