I have simple code for insert in database and it works fine;
static public void InsertUser(string userName, int age, DataGridView DadataGridView1)
{
try
{
if (connection.State == ConnectionState.Closed)
connection.Open();
MySqlCommand commandInsert = new MySqlCommand("INSERT INTO IP(Username,Age) VALUES(@Username,@Age)", connection);
commandInsert.Parameters.AddWithValue("@username", userName);
commandInsert.Parameters.AddWithValue("@age", age);
commandInsert.ExecuteNonQuery();
commandInsert.Parameters.Clear();
MessageBox.Show("User Inserted sucessfuly");
}
catch (MySqlException exception)
{
MessageBox.Show(exception.ToString());
}
finally
{
connection.Close();
}
}
I need write code for UPDATE and GET data. Please advice, I am a beginner in C #. Thanks.