更新未提交的mysql数据

时间:2016-08-20 13:10:06

标签: c# mysql

我一直在研究一些可以编辑我的mysql数据库中的数据的工具除了更新数据之外的一切都有效说我通过程序编辑了表格编辑了它赢得的条目的名称并不更新这个到目前为止,如果有人能提供帮助,我将非常感谢。

private void button4_Click(object sender, EventArgs e)
        {
            try

            {

                string MyConnection2 = "datasource=localhost;port=3306;username=root;password=toor";

                //Display query 

                string Query = "select * from truck.jobs;";

                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);

                MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);



                //  MyConn2.Open(); 

                //For offline connection we weill use  MySqlDataAdapter class. 

                MySqlDataAdapter MyAdapter = new MySqlDataAdapter();

                MyAdapter.SelectCommand = MyCommand2;

                DataTable dTable = new DataTable();

                MyAdapter.Fill(dTable);





                dataGridView1.DataSource = dTable; // here i have assign dTable object to the dataGridView1 object to display data. 



                // MyConn2.Close(); 

            }

            catch (Exception ex)

            {



                MessageBox.Show(ex.Message);
            }
        }

数据库中使用的当前表是id,Name,PlayerUID,JobsCompleted,MoneyEarned,CargoWeight,DrivenDistance 我使用数据网格来查看工具中的数据 这是工具的图像 click here for image

2 个答案:

答案 0 :(得分:0)

点击更新按钮,点击此处

MyAdapter.Update(dTable)

答案 1 :(得分:0)

好的,我必须输入我要输入的数据的ID,这是我的问题