當前位置:首頁 » 操作系統 » vb連接mysql資料庫

vb連接mysql資料庫

發布時間: 2023-10-14 04:13:54

A. vb的ADO控制項如何連接操作MYsql資料庫

由於ADO對象不直接支持MySQL,所以必須先安裝MyODBC, 後者也是一個免費產品,在 www.mysql.org上有下載,安裝好了MyODBC, 就可以在ODBC數據源管理中配置一個數據源名稱,把它指向你想連接的MySQL資料庫。代碼如下:Sub connectMySQL() '通過MyODBC去連接MySQL資料庫,並將Microsoft SQL Server 7 '的數據轉進mysql中 Dim sConnect As String, sSql As String, i As Long Dim cnMSSQL As New ADODB.Connection Dim cnMySQL As New ADODB.Connection '聲明並創建對象 連接 Dim rs As New ADODB.Recordset '聲明並創建對象 記錄集 Dim cm As New ADODB.Command '聲明並創建對象 命令 sConnect = "dsn=mysql1" '指定MySQL的數據源名稱 cnMySQL.Open sConnect '連接到 mysql sConnect="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=123456;Initial Catalog=softdown;Data Source=ntserver" '連接到 ms sql server 7 cnMSSQL.Open sConnect 'sSql = "create table softinfo (softNum smallint,softname varchar(70),softdesc blob," & _ "softpath varchar(30),softleng varchar(10),softclass varchar(10),softsugest tinyint(1)," & _ "softdown smallint(4))" '創建新的MySQL數據表語句 sSql = "select * from softinfo order by softnum" rs.Open sSql, cnMSSQL, 1, 1 While Not rs.EOF sSql = "insert into softinfo values (" & Trim(rs(0).Value) & ",'" & Trim(rs(1).Value) & _ "','" & Trim(rs(2).Value) & "','" & Trim(rs(3).Value) & "','" & Trim(rs(4).Value) & _ "','" & Trim(rs(5).Value) & "'," & Trim(rs(6).Value) & "," & Trim(rs(7).Value) & ")" cm.ActiveConnection = cnMySQL cm.CommandType = adCmdText cm.CommandText = sSql cm.Execute rs.MoveNext Wend rs.Close Set rs = Nothing cnMySQL.Close Set cnMySQL = Nothing cnMSSQL.Close Set cnMSSQL = Nothing End Sub

熱點內容
java修飾 發布:2025-01-23 07:45:03 瀏覽:183
oppor9s照片加密 發布:2025-01-23 07:37:57 瀏覽:712
javahtml亂碼 發布:2025-01-23 07:37:56 瀏覽:539
sqlserverc 發布:2025-01-23 07:34:15 瀏覽:699
mysql怎麼用資料庫 發布:2025-01-23 07:21:02 瀏覽:998
怎麼訪問暗網 發布:2025-01-23 07:02:04 瀏覽:666
無線配置代理選什麼 發布:2025-01-23 06:52:54 瀏覽:825
c程序匯編程序 發布:2025-01-23 06:49:42 瀏覽:841
cmd命令與linux命令 發布:2025-01-23 06:40:26 瀏覽:807
linux用戶目錄許可權 發布:2025-01-23 06:37:49 瀏覽:234