frank754 0 Newbie Poster

There are tons of posts in many forums about this, and I'm sure it can be done easily with custom code for each button, but if Visual Studio has any merits, this should be much easier.
What I'm trying to do is update some fields in gridview, then next time I start up or debug to have the changes made. Nothing seems to work, but from many posts from the best minds, so far I put this together:

public Form1()
        {
            InitializeComponent();
            string MyConString = "SERVER=localhost;" +
                    "DATABASE=xxxxx;" +
                    "UID=root;" +
                    "PASSWORD=xxxxxx;";
            MySqlConnection mysqlCon = new MySqlConnection(MyConString);
            MySqlDataAdapter MyDA = new MySqlDataAdapter();
            mysqlCon.Open();
            string custdata = "custdata";
            string squery = "SELECT * FROM custdata";
            MyDA.SelectCommand = new MySqlCommand(squery, mysqlCon);
            MySqlCommandBuilder builder = new MySqlCommandBuilder(MyDA);
            string sqlSelectAll = "SELECT * from custdata";
            MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon);
            string updateCommandMySql = builder.GetUpdateCommand(true).CommandText;
            string insertCommandMySql = builder.GetInsertCommand(true).CommandText;
            string deleteCommandMySql = builder.GetDeleteCommand(true).CommandText;
            DataSet table = new DataSet();
            table.Tables.Add("custdata");
            MyDA.Fill(table,"custdata");
            DataTable myDataTable = table.Tables[0];
            dataGridView1.DataSource = myDataTable;
            DataSet table2 = new DataSet();
            table2.Tables.Add(myDataTable.Copy());
            string UpdateCommand = builder.GetUpdateCommand().CommandText;
// I need this to save the data to the database
            MyDA.Update(table2, custdata);
            mysqlCon.Close();
            
            

        }

Somehow there must be something simple I have overlooked, or else I may need to validate all fields on the gridview (to avoid nulls), or perhaps just code it all by hand, using buttons, input fields, and opening/closing the connection from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.