gpt4 book ai didi

mysql - 插入 MySql 数据库 DataGrid 值

转载 作者:行者123 更新时间:2023-11-29 23:22:45 25 4
gpt4 key购买 nike

我想将我在数据 GridView 中输入的值添加到 mysql 数据库。

enter image description here

要删除当前选定的 ID,我使用此代码。

       Dim reader As MySqlDataReader
Try
SqlConn.Open()
Dim query As String
query = "delete from where id='" & DataGridView1.CurrentRow.Index & "'"
Dim command As New MySqlCommand
command = New MySqlCommand(query, SqlConn)
reader = command.ExecuteReader
MessageBox.Show("Data deleted")
ucitaj()
SqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
SqlConn.Dispose()
End Try

但是如何直接从数据 GridView 添加。我在空白字段中输入值,当我单击“添加”时,我想添加它。我知道要添加 mysql 数据库我需要使用这个查询

query = "insert into base (id, Username, password, Link) values(Which ones ?)"

最佳答案

这又快又脏。事实上你应该参数化执行此操作

你只需选择它,这样当前行就不是空的

    If Not DataGridView1.CurrentRow Is Nothing Then
Dim id As Integer = DataGridView1.CurrentRow.Cells("ID").Value
Dim username As String = DataGridView1.CurrentRow.Cells("username").Value
Dim pw As String = DataGridView1.CurrentRow.Cells("password").Value
Dim link As String = DataGridView1.CurrentRow.Cells("Link").Value

Dim sqlstr As String = "insert into base (id, Username, password, Link) values(" & id & "," & username & "," & pw & "," & link & ")"
'your code
End If

关于mysql - 插入 MySql 数据库 DataGrid 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27189218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com