必须安装MYSQL的驱动才行,不管是VB还是c++都需要这个驱动。代码如下: Public Function exemysql(ByVal sql As String) As ADODB.Recordset sql = Trim$(sql) Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.Open "Driver=MySQL ODBC 3.51 Driver" &_ "Server=服务器地址" &_ "Port=3306" &_ "Database=
数据库名" &_ "Uid=用户名" &_ "Pwd=密码" conn.DefaultDatabase = "数据库名" conn.CursorLocation = adUseClient Set rs.ActiveConnection = conn rs.LockType = adLockBatchOptimistic rs.CursorType = adOpenKeyset rs.Open sql Set exesql = rs Set rs = Nothing Set conn = Nothing End FunctionImports System.Data.OleDb
Public Class Form1
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=c:\TSXS.mdbPersist Security Info=False"
Dim conn As New OleDbConnection(connStr)
Dim com As New OleDbCommand("delete from 入库 where 编号='011'", conn)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.Open()
com.ExecuteNonQuery()
conn.Close()
End Sub
End Class
测试可用 单引号是查询字段为字符串类型时给内容的前后加单引号 而不是在 表名 或者 字段名前后加
评论列表(0条)