none
【求助】dataGridView连接mysql数据库不能更新 RRS feed

  • 问题

  • 代码如下,点击button后,dataGridView不能更新,求助

    public partial class Form1 : Form
    {
      MySqlDataAdapter daCountry;
      DataSet dsCountry;
      private void Form1_Load(object sender, EventArgs e)
      {
          string myConnectionString;
          myConnectionString = "server=127.0.0.1;uid=root;pwd=123456;database=db1;";
          MySqlConnection conn = new MySqlConnection(myConnectionString);
    
          try
          {
            string sql = "SELECT process, fileDir FROM file WHERE clientName='SIYUAN'";
            daCountry = new MySqlDataAdapter(sql, conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(daCountry);
    
            dsCountry = new DataSet();
            daCountry.Fill(dsCountry, "file");
    
            dataGridView1.DataSource = dsCountry;
            dataGridView1.DataMember = "file";
          }
    
          catch (Exception ex)
          {
            label1.Text = ex.ToString();
          }
      }
    
     private void button1_Click(object sender, EventArgs e)
        {
          daCountry.Update(dsCountry, "file");
        }
    }
    

    2010年8月12日 2:43

答案

全部回复