C# 如何在c中保存数据网格视图和文本框中的数据#

C# 如何在c中保存数据网格视图和文本框中的数据#,c#,mysql,C#,Mysql,我有一个3个文本框和一个多栏的数据网格视图,我需要使用MySql将数据保存到数据库中 我可以使用按钮1中的Update quire将数据从文本框保存到数据库,使用按钮2从数据网格视图保存或更新数据,但我需要一些东西来更新和保存MySql中多个表中的数据(数据网格视图)和(文本框)。请在此处输入代码 try { string conn = "Server=" + GlobalsForServerInfo.Server + "; Port=" + Globa

我有一个3个文本框和一个多栏的数据网格视图,我需要使用MySql将数据保存到数据库中 我可以使用按钮1中的Update quire将数据从文本框保存到数据库,使用按钮2从数据网格视图保存或更新数据,但我需要一些东西来更新和保存MySql中多个表中的数据(数据网格视图)和(文本框)。请在此处输入代码

 try
        {
            string conn = "Server=" + GlobalsForServerInfo.Server + "; Port=" + GlobalsForServerInfo.Port + "; Database=" + GlobalsForServerInfo.Database + "; Uid=" + GlobalsForServerInfo.Username + "; Pwd=" + GlobalsForServerInfo.Password + ";";
            string Query = "INSERT INTO accounting_sys.add_new_voucher (Voucher_Id,Voucher_Number,Date,Time,Status,Suppliers,Type) values('" + this.txtVoucherId.Text + "' ,'" + this.txtVouNo.Text + "'   ,    '" + this.dtpDateFrom.Text + "'   ,   '" + this.timeEdit1.Text + "'    ,    '" + this.txtStatus.Text + "','" + this.txtSuppliers.Text + "','" + Type + "') ;";
            MySqlConnection MyConn2 = new MySqlConnection(conn);
            MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
            MySqlDataReader MyReader2;
            MyConn2.Open();
            MyReader2 = MyCommand2.ExecuteReader();
            MessageBox.Show("Data Saved");
            while (MyReader2.Read())
                MyConn2.Close();

        }

        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }

    }
/


永远不要连接SQL查询/连接字符串。使用参数化字符串(
string.Format()
)你能给我演示一下如何用正确的方式来做吗
 private vobutton4_Clickid (object sender, EventArgs e)
        if (txtboxCredit.Text == textboxDebit.Text)
        {
            try //Try section 1 of operation
            {
                dataGridView1.EndEdit(); //very important step
                da.Update(dataTable);
                MessageBox.Show("Data Updated");
                DataBind();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }
        else
            MessageBox.Show(" Make sure that debit and credit account balances are in the appropriate debit and credit columns of the trial balance calculation. Check for reversed digits and misplaced decimal points.", "Error in transferring account balances to proper trial balance columns",
MessageBoxButtons.OK, MessageBoxIcon.Error);
    }