title: No row can be added to a DataGridView control that does not have columns. Columns must be added first. in VB.net
body: <p>I have been encountering an error in my VB.Net code that says &quot;No row can be added to a DataGridView control that does not have columns. Columns must be added first.&quot;. When I was trying to code a live search on a datagridview1. Please help me.</p>
  <p>Here is the code for the datagrid live search that encounters an error:</p>
  <pre><code>Private Sub txt_search_TextChanged(sender As Object, e As EventArgs) Handles txt_search.TextChanged
      DataGridView1.Rows.Clear()
      '' Searching via room number or category id, ie room type
      Try
          conn.Open()
          Dim cmd As New MySqlCommand(&quot;SELECT r.id, r.room_no, c.name, r.description, r.price FROM categories c JOIN rooms r ON c.id = r.category_id WHERE room_no LIKE '%&quot; &amp; txt_search.Text &amp; &quot;%' or name LIKE '%&quot; &amp; txt_search.Text &amp; &quot;%'&quot;, conn)
          dr = cmd.ExecuteReader
          While dr.Read
              DataGridView1.Rows.Add(dr.Item(&quot;ID&quot;), dr.Item(&quot;room_no&quot;), dr.Item(&quot;name&quot;), dr.Item(&quot;description&quot;), dr.Item(&quot;price&quot;))
          End While
          dr.Dispose()
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
      conn.Close()
  End Sub
  </code></pre>