Answer the question
In order to leave comments, you need to log in
How to save changes in DataGrid VC#?
Goodnight! Pulled out from a database in a column. Everything is displayed well. But after editing - it is not saved naturally. How to use the example of my code to implement something like DbDataAdapter.Update (DataTable) to put the SAVE button and naturally all changes, additions and deletions were saved in MySQL. Here is the code:
private DataTable GetCats()
{
DataTable dt = new DataTable();
MySqlConnectionStringBuilder mysqlCSB;
mysqlCSB = new MySqlConnectionStringBuilder();
mysqlCSB.Server = textBox1.Text;
mysqlCSB.Database = textBox2.Text;
mysqlCSB.UserID = textBox3.Text;
mysqlCSB.Password = textBox4.Text;
string queryString = @"SELECT blablabla FROM blablabla WHERE blabla IN (SELECT blabla FROM blablabla WHERE blablabla='blablabla')";
using (MySqlConnection con = new MySqlConnection())
{
con.ConnectionString = mysqlCSB.ConnectionString;
MySqlCommand com = new MySqlCommand(queryString, con);
try
{
con.Open();
using (MySqlDataReader dr = com.ExecuteReader())
{
if (dr.HasRows)
{
dt.Load(dr);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
return dt;
}
Answer the question
In order to leave comments, you need to log in
public static void SQLSendData(string ConnectionString, string CommandString)
{
using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
try
{
MySqlCommand command = new MySqlCommand(CommandString, connection);
command.Connection = connection;
connection.Open();
rowsAffected = command.ExecuteNonQuery();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
finally
{
connection.Close();
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question