gpt4 book ai didi

mysql - 如何从datagridview插入数据到数据库mysql vb.net

转载 作者:行者123 更新时间:2023-11-29 18:38:47 25 4
gpt4 key购买 nike

这是我的代码

MysqlConn.Open()
command.Connection = MysqlConn
command.CommandText = CommandType.Text
command.CommandText = "INSERT INTO order VALUES (@1,@2,@3,@4,@5,@6,@7,@8)"
command.Parameters.AddWithValue("@1", rw.Cells(0).Value)
command.Parameters.AddWithValue("@2", rw.Cells(1).Value)
command.Parameters.AddWithValue("@3", rw.Cells(2).Value)
command.Parameters.AddWithValue("@4", rw.Cells(3).Value)
command.Parameters.AddWithValue("@5", Now())
command.Parameters.AddWithValue("@6", TextBox6.Text)
command.Parameters.AddWithValue("@7", TextBox7.Text)
command.Parameters.AddWithValue("@8", TextBox8.Text)

command.ExecuteNonQuery()
Next
MsgBox("done")
MysqlConn.Close()

command.Parameters.Clear()

我已经完成了“插入顺序(名称,.....)值(@1,....),但仍然无法正常工作。我正在使用mysql

最佳答案

       Dim I As Integer
For I = 0 To Dgrd.Rows.Count - 2
Dim row As DataGridViewRow = Dgrd.Rows(I)
Dim SQLCON As New SqlConnection(MyDataBaseCon)
Dim CMD As SqlCommand
Dim S1 As DataGridViewTextBoxCell = row.Cells(1)
Dim S2 As DataGridViewTextBoxCell = row.Cells(2)
Dim S3 As DataGridViewTextBoxCell = row.Cells(3)
CMD = New SqlCommand("Insert Into order
(S1,S2,S3) Values (@S1,@S2,@S3)", SQLCON)
SQLCON.Open()
CMD.Parameters.Add(New SqlParameter("@S1", SqlDbType.Int)).Value = S1
CMD.Parameters.Add(New SqlParameter("@S2", SqlDbType.Int)).Value = S2
CMD.Parameters.Add(New SqlParameter("@S3", SqlDbType.NVarChar, 50)).Value = S3

CMD.ExecuteNonQuery()
SQLCON.Close()

Next
MsgBox("done")

关于mysql - 如何从datagridview插入数据到数据库mysql vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45070515/

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