当前位置:Gxlcms > mysql > mysql-请教VB2013中MySqlClient的用法(读取,修改,添加,删除等)

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

时间:2021-07-01 10:21:17 帮助过:39人阅读

mysqlvb net

请问如何使用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 MySqlDataReader1)        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)

人气教程排行