title: How to save data entry to MySQL database
body: <p>I have an assignment where I have to develop a Windows application using Visual Basic .NET. From the form that I have designed, it should save all records in a table in a MySQL database. How should I do this? Here's what I've got so far:</p>
  
  <pre class="lang-vb.net prettyprint-override"><code>Imports System.Data
  Imports System.Data.SqlClient
  
  Public Class AddMember
      Dim con As New SqlConnection
      Dim cmd As New SqlCommand
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          con.ConnectionString = "Data Source=|DataDirectory|\127.0.0.1"
  
          con.Open()
  
          cmd.Connection = con
          cmd.CommandText = "INSERT INTO memberdetails (ID, Name, Surname, Age, Gender, Contact, Address) VALUES (@ID, @Name, @Surname, @Age, @Gender, @Contact, @Address)"
  
          cmd.Parameters.AddWithValue("@ID", TextBox1.Text)
          cmd.Parameters.AddWithValue("@Name", TextBox2.Text)
          cmd.Parameters.AddWithValue("@Surname", TextBox3.Text)
          cmd.Parameters.AddWithValue("@Age", TextBox4.Text)
          cmd.Parameters.AddWithValue("@Gender", ComboBox1.Text)
          cmd.Parameters.AddWithValue("@Contact", TextBox6.Text)
          cmd.Parameters.AddWithValue("@Address", TextBox7.Text)
          cmd.ExecuteNonQuery()
  
          con.Close()
  
          MsgBox("Added Successfully")
      End Sub
  End Class
  </code></pre>
  
  <p><strong>con.Open()-error 26</strong></p>