1

So I am making an application that shows a viral video each day.It uses a MySQL database keep count on the views, I have a MySQL database with a column called video1_count with only 1 value. I want to know how to add to the current int not add new data I have a class called add user that I will use to execute the code how can I do this?

I did find this Post But for the life of me i could not get it to work.

i Tried this code :

MySqlConnection connect = new MySqlConnection(Connect_String);
MySqlCommand cmd = new MySqlCommand();

cmd.Connection = connect;
cmd.Connection.Open();

string commandLine = null;
string commmandLine = "UPDATE Youtube SET Video1_count = Video1_count + 1 ";
cmd.Set // (Recommended by a user) but cmd.set is not valid 

cmd.Connection.Close(); 
1
  • show how did you try, then people may see what was wrong and suggest on how to fix it Commented Apr 21, 2014 at 0:24

1 Answer 1

1

You're not executing a command anywhere.

command.ExecuteNonQuery() will actually send your command to the database

Try this

MySqlConnection connection = new MySqlConnection(Connect_String);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "UPDATE Youtube SET Video1_count = Video1_count + 1";
connection.Open();
command.ExecuteNonQuery();
connection.Close();
Sign up to request clarification or add additional context in comments.

5 Comments

"No database selected"
oh name of the database is Slq4342562 and the table name is Youtube and the column is called Video1_count how would this go, sorry i am new to using MySQL in my applications
@Gerard2202 Check your connection string, does it mention database name Slq4342562?
@har07 here is my string for the connection String Connect_String = "datasource=sql3.freesqldatabase.com;port=******;username=******;password=********";
Looks like a bad connection string. Check out the options on connectionstrings.com, under MySQL. General format appears to be along the lines of "Server=sql3.freesqldatabase.com;Port=****;Database=Sql4342562;Uid=****;Pwd=****;"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.