怎么用dataGridView批量添加数据或批量修改数据

2025-03-26 00:25:19
推荐回答(2个)
回答1:

测过,成功。
 private void btnSaveEmploy_Click(object sender, EventArgs e)
        {
            DataTable dt = grcAlterEmploy.DataSource as DataTable;
            dt.TableName = "Employers";
            DataSet set = new DataSet();
            set.Tables.Add(dt);
            UpdateByDataSet(set, "Employers", DbHelper.connectionString);
        }
public void UpdateByDataSet(DataSet ds, string strTblName, string strConnection)
{
    SqlConnection conn = new SqlConnection(strConnection);
            SqlDataAdapter myAdapter = new SqlDataAdapter();
            SqlCommand myCommand = new SqlCommand("select * from " + strTblName, conn);
            myAdapter.SelectCommand = myCommand;
            SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
            myAdapter.Update(ds, strTblName); 
        }

回答2:

数据库中用sqlcommand命令