问题:我想从我制作的程序(新的)编辑MySQL数据库表中的变量(数字)。什么可以让我接收当前变量然后在线编辑数据库。
代码使用:
Imports System.Data.SqlClient
Imports mysql
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim MySQLConnection = New SqlClient.SqlConnection
MySQLConnection.ConnectionString = "server=db4free.net ;port=3306; user id=user; password=password; database=databasetest;"
MySQLConnection.Open()
MsgBox("Success!")
Catch ex As Exception
MsgBox("Failed!")
End Try
End Sub
End Class
编程语言:Visual Studios 13
答案 0 :(得分:0)
看起来你是用VB编写的。要与数据库交互,您需要发送SQL命令。为了向它发送SQL命令,您需要SqlClient.SqlCommand
。打开与数据库的连接后,您的代码将类似于以下内容,以更新特定表上特定字段的值:
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = MySQLConnection
cmd.CommandText = "UPDATE <your table> SET <your field> = <your number> WHERE <however you would specify the record that needs to be changed>;"
Try
cmd.ExecuteNonQuery()
Catch ex As SqlClient.SqlException
'Deal with whatever error pops up
End Try