2 a243038357 a243038357 于 2015.06.02 14:53 提问

请教VB2013 中 MySqlClient 的用法(读取,修改,添加,删除等)

请问如何使用MySqlClient实现如下功能:
已知连接参数
Public sql As String = "server=192.168.2.97;user id=root;password=root;persistsecurityinfo=True;port=3306;database=school"
表名 children
图片说明
1) 读取 Index=1 行 age 值
2) 写入一行新数据“Index=7;name=ght;age=12;sex=girl”
3) 将 Index=4 行的 age 数据修改为12
4) 查询表中 age=12 的数据行有多少
5) 将 Index=4 行数据从数据库中删除
现有资料都是通过ADODC连接,但是项目要求使用MySqlClient来做
现有已经实现的功能1,2,的源码如下(非此题代码,是我的项目源码),但是其它的不会写了

    '数据库相关
    Public sql As String = "server=192.168.2.97;user id=root;password=nbjgtyndatabase;persistsecurityinfo=True;port=3307;database=nbjgtyn"
    Public mcn As MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection(sql)
    Public sqlstr As String = "select * from Zhi_Liu_Ce_Liang where Datatime = '" & DateTime.Now & "'"
    Public mda As MySqlDataAdapter
    Public dt As DataTable
    Public Entry As String = "aaaa" '数据库中存储本机设置的条目查询字

    Public astr As String = "select * from Config where Name = '" & Entry & "'"
    Public mcmd As MySqlCommand
    Public mdr As MySqlDataReader

1)
        mcn.Open()
        mcmd = New MySqlCommand(astr, mcn)
        mdr = mcmd.ExecuteReader
        mdr.Read()
        Local_Port = mdr.Item("Port")
        KeyWord = mdr.Item("Keyword")
        mcn.Close()

    2)
             mda = New MySqlDataAdapter(sqlstr, mcn)
        dt = New DataTable
        mda.Fill(dt)
        Dim dr As DataRow = dt.NewRow()
        dr.Item("Number") = sender.Number
        dr.Item("Datatime") = DateTime.Now
        dr.Item("Current") = sender.Current
        dr.Item("Voltage") = sender.Voltage
        dr.Item("Power") = sender.Power
        dt.Rows.Add(dr)
        Dim cb As MySqlCommandBuilder = New MySqlCommandBuilder(mda)
        mda.Update(dt)

1个回答

caozhy
caozhy   Ds   Rxr 2015.06.02 18:33
已采纳

和SqlClient类似。除了连接字符串不同,你可以google

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!