根據查詢條件批量修改表資料

dandan00056發表於2019-07-11

--表:table 

--欄位:columsA、columsB、columsC、columsD

void Main(){

string sql="select columsA from table";

DataTable dt=SqlHelper.executeQuery(sql);

dt.rows[0]["columsA"]="111";

sdaUpdate(sql,dt)

}

 

public void sdaUpdate(string selectSql,DataTable dt)
{
  try
  {
    SqlCommand sqlCommand = GetSqlConn().CreateCommand();
    sqlCommand.CommandText = selectSql;

    SqlDataAdapter sdaAdapter = new SqlDataAdapter(sqlCommand);

    SqlCommandBuilder scbBuilder = new SqlCommandBuilder(sdaAdapter);

    sdaAdapter.Update(dt);
}
catch (Exception ex)
{

}
}

 

相關文章