Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click
Dim Query As String
mysqlconn.Open()
Query = "insert into details(id,s1,c1)values('" & txt_.Text & "','" & txt1.Text & "','" & txt2.Text & "')"
Dim cmd As MySqlCommand = New MySqlCommand(Query, mysqlconn)
Dim i As Integer = cmd.ExecuteNonQuery()
mysqlconn.Close()
If (i > 0) Then
MsgBox("Record is Successfully added")
mysqlconn.Open()
Dim strSQL As String = "SELECT * from details "
Dim cmd1 As New MySqlCommand(strSQL, mysqlconn)
Dim reader As MySqlDataReader = cmd1.ExecuteReader
Dim table1 As New DataTable()
table1.Load(reader)
datagridview1.DataSource = table1
' datagridview1.RefreshEdit()
mysqlconn.Close()
mysqlconn.Dispose()
Else
MsgBox("Record is not added")
End If
mysqlconn.Close()
end sub
我有两种形式:Form1
和Form2
.
Form1
- 在上面的代码中,当我点击添加按钮后,在文本框中输入的id、txt1、txt2被保存到详细信息表中。(mysql数据库)
同时,我想将该条目插入到位于Form2
.
我在 msgbox “成功添加”之后写了一些代码。执行相同的代码时我没有收到错误,但在运行时没有在 datagridview 中添加行。