I have a method Insert(). Everything is working as expected except for the auto increment. Here's the code:  
public void Insert(string m1,int y1,int new_count)
    {
        string query = "INSERT INTO page_counter (id,month,year,page_count) VALUES('','"+m1+"',"+y1+","+new_count+")";
            //create command and assign the query and connection from the constructor
            MySqlCommand cmd = new MySqlCommand(query, connection);
            //Execute command
            cmd.ExecuteNonQuery();
            //close connection
            this.CloseConnection();
    }  
My Id column is an auto-increment. So my question is how can the value be inserted in the database an continue the auto increment in the table for id?
Simply don't specify value for id :
string query = "INSERT INTO page_counter (month,year,page_count) VALUES('"+m1+"',"+y1+","+new_count+")";
And look into better approach, parameterized query, instead of concatenating query string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With