title: Insert Values into database
body: <p>I have been using the following code to insert the values into the MySQL database. The code builds with no error message but as soon as I try to run the code it says:</p>
  
  <blockquote>
    <p>MySql.Data.MySqlClient.MySqlException: Column 'name' cannot be null</p>
  </blockquote>
  
  <p>Please tell me the error in my code.</p>
  
  <p>Here is the insert function that i am using:</p>
  
  <pre><code>public int insert (int id, string name, string sname, int marks )
  {
       string connection= ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
         MySqlConnection con = new MySqlConnection(connection);
  
  
      MySqlCommand com = new MySqlCommand("INSERT INTO Student_details(id,name,sname,marks) values(@id,@name, @sname, @marks)");
  
     // com.Connection = com;
     com.Connection = con;
      con.Open();
  
      //com.Parameters.Add("@id", id);
      //com.Parameters.Add("@name", name);
      //com.Parameters.Add("@sname", sname);
      //com.Parameters.Add("@marks", marks);
      com.Parameters.AddWithValue("@id", id);
      com.Parameters.AddWithValue("@name", name);
      com.Parameters.AddWithValue("@sname", sname);
      com.Parameters.AddWithValue("@marks", marks);
     //// com.Parameters.a
      //com.ExecuteNonQuery();
      int ret = Convert.ToInt32(com.ExecuteScalar());
  
      return ret;
  }
  </code></pre>