title: Trouble Inserting Data into MySqlDatabase with parameters in ASP.net (vb.net)
body: <p>I'm having some problems when I try to insert data to my database(mysql). It seems my connection isn't working, but I doubt it because I can retrieve data from it yet no luck on inserting.
  I've also tried various things and I still can't come up with a solution nor find the cause of error.</p>
  <p>Can somebody help me out? Your concern is very much appreciated!</p>
  <h2>Here's my Registration.aspx page</h2>
  <pre><code>Imports MySql.Data.MySqlClient
  Imports System.Web.Security
  Imports System.Security.Cryptography
  Imports System.Web.Configuration
  Imports System.Configuration
  Partial Class Register
      Inherits System.Web.UI.Page
      Dim ctc As New Class1
      Dim conn As MySqlConnection
      Dim connstr As String = ConfigurationManager.ConnectionStrings(&quot;dbconn&quot;).ConnectionString
      Dim cmd As MySqlCommand
      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  
          Try
              conn = New MySqlConnection(connstr)
              conn.Open()
  
              cmd = New MySqlCommand(&quot;INSERT INTO tbl_uinfo (user_id, fname, lname, email, pword, paypal) values (null,@fname,@lname,@email,@pword,@paypal)&quot;)
              cmd.Parameters.Add(&quot;@fname&quot;, MySqlDbType.VarChar, 45).Value = firstname.Text
              cmd.Parameters.Add(&quot;@lname&quot;, MySqlDbType.VarChar, 45).Value = lastname.Text
              cmd.Parameters.Add(&quot;@email&quot;, MySqlDbType.VarChar, 45).Value = email.Text
              cmd.Parameters.Add(&quot;@pword&quot;, MySqlDbType.VarChar, 250).Value = password2.Text
              cmd.Parameters.Add(&quot;@paypal&quot;, MySqlDbType.VarChar, 45).Value = paypal.Text
  
              cmd.ExecuteNonQuery()
  
  
  
              conn.Dispose()
              conn.Close()
              cmd.Dispose()
          Catch ex As Exception
              MsgBox(&quot;Registration failed.&quot; &amp; ex.Message)
          End Try
  
      End Sub
  End Class
  </code></pre>
  <hr />
  <h2>Here's my ConnectionString (web.config)</h2>
  <pre><code>&lt;connectionStrings&gt;
          &lt;add name=&quot;dbconn&quot; connectionString=&quot;server=localhost;database=db_aspweb;user id=root; pwd=root&quot;/&gt;
      &lt;/connectionStrings&gt;
  </code></pre>
  <hr />
  <h2>My Database</h2>
  <pre><code>CREATE TABLE `tbl_uinfo` (
    `user_id` int(11) NOT NULL AUTO_INCREMENT,
    `fname` varchar(45) DEFAULT NULL,
    `lname` varchar(45) DEFAULT NULL,
    `email` varchar(45) DEFAULT NULL,
    `pword` varchar(250) DEFAULT NULL,
    `paypal` varchar(45) DEFAULT NULL,
    PRIMARY KEY (`user_id`),
    UNIQUE KEY `email` (`email`),
    UNIQUE KEY `paypal` (`paypal`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  <hr />
  <h2>The error I am getting so far</h2>
  <p>&quot;Registration Failed. Connection must be valid and open.&quot;</p>