我向在datagridview中输入数据,然后点击保存按钮,把数据保存到数据库中,请各位能给个实例吗?谢谢!

解决方案 »

  1.   

    for(int i=0;i<this.dataGridView.Rows.count;i++)
    {
    string a=textBoxEmpID.Text ;
    string b=this.dataGridView1.Rows[i][0].ToString();
    string c=this.dataGridView1.Rows[i][1].ToString();
    string d=this.dataGridView1.Rows[i][2].ToString();
    insert into Salary(EmployeeID,Income,Outcome,Note3) values(a,b,c,d)
    }
      

  2.   

    LZ可以百度,这样的问题用不着来CSDN。BAIDU一搜一大框
      

  3.   

    谢谢jmlovews的回复!我百度到了你说的答案,我的表字段很长,感觉这样做很麻烦,我想来这里问问看有没有简单的方法!
    非常感谢你的及时回答!
      

  4.   

    DataSet ds = new DataSet();
    SqlDataAdapter sda;SqlCommandBuilder scb = new SqlCommandBuilder(sda);
    sda.Update(ds);
    this.dataGridView1.DataSource = ds.Tables[0];
      

  5.   

    for(int i=0;i<this.dataGridView.Rows.count;i++)
    {
    string a=textBoxEmpID.Text ;
    string b=this.dataGridView1.Rows[i][0].ToString();
    string c=this.dataGridView1.Rows[i][1].ToString();
    string d=this.dataGridView1.Rows[i][2].ToString();
    insert into Salary(EmployeeID,Income,Outcome,Note3) values(a,b,c,d)
    }