title: Insert into mysql table using c#
body: <p>I'm trying to insert some data to my MySql table using C# but I'm facing some problems
  I've added the MySql.Data.MySqlClient reference.</p>
  
  <p>I've gone through some tutorials on the web and I found some codes like <code>cmd.Parameters.AddWithValue</code>; however when I try to write this code it does not show up any idea why? It only shows <code>.Add</code>.</p>
  
  <p>I've created a simple table 'inf' which has a id, name and surname where id is the primary key and it's on <code>autoIncrement</code>. My code is as follows:</p>
  
  <pre><code>string connString = "Server=localhost;Database=insertdeneme;Uid=****;Pwd=********;";
  MySqlConnection mcon = new MySqlConnection(connString);
  mcon.Open();
  
  string cmdText = "INSERT INTO inf VALUES (null, @name, @surname)";
  MySqlCommand cmd = new MySqlCommand(cmdText, mcon);
  cmd.Parameters.Add("@name", txtname.Text);
  cmd.Parameters.Add("@surname", txtsurname.Text);
  cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>The program compiles however when I press on the button I get the following error:</p>
  
  <blockquote>
    <p>Column count doesn't match value count at row 1</p>
  </blockquote>
  
  <p>When I remove the null from values I get:</p>
  
  <blockquote>
    <p>Column 'name' cannot be null</p>
  </blockquote>
  
  <p>So what do you think is the problem with the code?</p>
  
  <p>Edited: I have one form, two text boxes and a button (txtname.text,txtsurname.text, btn.register). I added the <code>mysql.data.mysqlclient</code> reference.</p>
  
  <p>I created a database using phpMyAdmin, and in my table I have id name and surname where id is primary and on auto increment with 11 digits and name surname are type of varchar with the limitation of 255 chars and the rest of the code are above.</p>
  
  <p>What I also don't understand is why am I not able to use <code>addwithvalue</code>.</p>
  
  <blockquote>
    <p>Error 1   'MySql.Data.MySqlClient.MySqlParameterCollection' does not contain a definition for 'addWithValue' and no extension method 'addWithValue' accepting a first argument of type 'MySql.Data.MySqlClient.MySqlParameterCollection' could be found (are you missing a using directive or an assembly reference?) C:\Users\FOREVER\documents\visual studio 2010\Projects\InsertInto1\InsertInto1\Form1.cs 63  32  InsertInto1</p>
  </blockquote>