請問如何使用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)
和SqlClient類似。除了連接字符串不同,你可以google