title: How to insert rows in datagridview which is placed on form2 in vb.net as add button is on form1?
body: <pre><code> 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('" &amp; txt_.Text &amp; "','" &amp; txt1.Text &amp; "','" &amp; txt2.Text &amp; "')"
          Dim cmd As MySqlCommand = New MySqlCommand(Query, mysqlconn)
          Dim i As Integer = cmd.ExecuteNonQuery()
  
          mysqlconn.Close()
  
          If (i &gt; 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
  </code></pre>
  
  <p>I have two forms: <code>Form1</code> and <code>Form2</code>.</p>
  
  <p><code>Form1</code> - In the above code, after I click on add button, id, txt1, txt2 which are entered in textboxes are saved into the details table.(mysql database)</p>
  
  <p>At the same time I want to insert that entry in datagridview which is placed on <code>Form2</code>.</p>
  
  <p>I have written some code after msgbox "successfully added". I am not getting an error when executing the same code, but row is not getting added in datagridview during runtime.</p>