# How to update dbf file with powershell?

**URL:** <https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323>\
**Category:** PowerShell Help\
**Created:** [December 1, 2020, 8:25pm UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323 "2020-12-01T20:25:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![puad](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@puad](https://forums.powershell.org/u/puad)\
**Post date:** [December 1, 2020, 8:25pm UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323/1 "2020-12-01T20:25:01Z")

</div>

Hi At first I apologize for my English.

I am asking for help in solving my problem.

I have a simple script that reads data from the users.dbf file (via Microsoft.ACE.OLEDB.12.0).

For the user X it has to fill in the id\_sys field

**How do I update the users.dbf file?**

=====================================

$conn = new-object System.Data.OleDb.OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\CZM\_users;Extended Properties=dBase IV”)  
$conn.open()

$cmd = new-object System.Data.OleDb.OleDbCommand(“select \* from users”, $Conn)  
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)  
$dt = new-object System.Data.dataTable  
$da.fill($dt)

#$dt | select nazwisko,id\_sys #etc

foreach ($i in $dt)  
{  
if ($i.nazwisko -eq “Majewska Beata”)  
{  
$i.ID\_SYS = “MB”  
}  
}

**_??? # How to update the users.dbf file_**

$conn.Close()

========================================

&nbsp;

Thx Adam

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [December 2, 2020, 5:23am UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323/2 "2020-12-02T05:23:51Z")

</div>

Take a look at this:

> **[\#40 : Reading, Updating and Inserting Data into Excel with Powershell](http://powershell-tips.blogspot.com/2012/07/reading-updating-and-inserting-data.html)**
>
> We often find ourself into a situation when we have to create or write into Excel sheet. This tasks can be done with two ways - 1. Using E...

Not sure if the query is working for you, but the “Data Source” should reference the file and it’s just a path in your posted code.

---

<div class="post-metadata">

**Author:** ![puad](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@puad](https://forums.powershell.org/u/puad)\
**Post date:** [December 3, 2020, 9:43am UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323/3 "2020-12-03T09:43:50Z")

</div>

Thank you,

I will try tomorrow and write about my results.

thx

---

<div class="post-metadata">

**Author:** ![puad](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@puad](https://forums.powershell.org/u/puad)\
**Post date:** [December 4, 2020, 2:06am UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323/4 "2020-12-04T02:06:53Z")

</div>

Hi

Thank you @Rob Simmers

Your tip was very good.

Good job

My working script

```
#===================================

#sql query, generated earlier ...
$strQuery =
       "Update users set ID_SYS = 'ETFF' where NAZWISKO = 'Kowska Agnieszka'",
       "Update users set ID_SYS = 'HMSQ' where NAZWISKO = 'Kulka Elżbieta'"

$objConn = new-object System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\CZM_users;Extended Properties=dBase IV")

$objConn.open()

foreach ($i in $strQuery)
        {
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand($i.sq)
$sqlCommand.Connection = $objConn

$sqlCommand.ExecuteNonQuery() | Out-Null
        }

$objConn.Close()

#================================
```

&nbsp;

Thx

Adam

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/how-to-update-dbf-file-with-powershell/15323/5 "2024-05-16T20:28:11Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


