Problem is that I want to use PowerShell and a csv file to update a database
(Access, SQL, whatever). I do this now with VBScript. I have made a simple
example of the ps1 script and text file and it works BUT only inserts one
row. If the sample "simpleTest.ps1 " is run from powershell the extraction is
fine. I have commented out the database stuff which works when a instance of
Access "Adatabase" with a "Table1" with all fields set to datatype "text" has
been created, but only one row gets added. I have also tried this with a
do-while and do-until loops with movenext and eof stuff without success.
The csv file - "simpleList.txt " - contains:
a,1,2
b,3,4
c,5,6
d,7,8
e,8,0
The ps1 file - "simpleTest.ps1 " - contains:
#$adOpenStatic = 3
#$adLockOptimis tic = 3
#$objConnection = New-Object -com "ADODB.Connecti on"
#$objRecordSet = New-Object -com "ADODB.Recordse t"
#$objConnection .Open("Provider =Microsoft.Jet. OLEDB.4.0;Data Source =
c:\Adatabase.md b")
#$objRecordSet. Open("DELETE * FROM Table1", $objConnection, $adOpenStatic,
$adLockOptimist ic)
#$objRecordSet. Open("SELECT * FROM Table1", $objConnection, $adOpenStatic,
$adLockOptimist ic)
$toDay = Get-Date -Format yyMMdd
$fileA = "C:\SimpleList. txt"
#$objRecordSet. AddNew()
ForEach ($a in Get-Content $fileA)
{
$i = $a.split(",")
$toDay + " " + $i[0] + " " + $i[1] + " " + $i[2]
# $objRecordSet.F ields.Item("dat e").value = $toDay
# $objRecordSet.F ields.Item("fie ld01").value = $i[0]
# $objRecordSet.F ields.Item("fie ld02").value = $i[1]
# $objRecordSet.F ields.Item("fie ld03").value = $i[2]
# $objRecordSet.U pdate()
}
#$objRecordSet. Close()
#$objConnection .Close()
What am I missing? 1 3082
"leroycarl" <le*******@disc ussions.microso ft.comwrote in message
news:99******** *************** ***********@mic rosoft.com...
Problem is that I want to use PowerShell and a csv file to update a
database
(Access, SQL, whatever). I do this now with VBScript. I have made a
simple
example of the ps1 script and text file and it works BUT only inserts one
row. If the sample "simpleTest.ps1 " is run from powershell the extraction
is
fine. I have commented out the database stuff which works when a instance
of
Access "Adatabase" with a "Table1" with all fields set to datatype "text"
has
been created, but only one row gets added. I have also tried this with a
do-while and do-until loops with movenext and eof stuff without success.
The csv file - "simpleList.txt " - contains:
a,1,2
b,3,4
c,5,6
d,7,8
e,8,0
The ps1 file - "simpleTest.ps1 " - contains:
#$adOpenStatic = 3
#$adLockOptimis tic = 3
#$objConnection = New-Object -com "ADODB.Connecti on"
#$objRecordSet = New-Object -com "ADODB.Recordse t"
#$objConnection .Open("Provider =Microsoft.Jet. OLEDB.4.0;Data Source =
c:\Adatabase.md b")
#$objRecordSet. Open("DELETE * FROM Table1", $objConnection, $adOpenStatic,
$adLockOptimist ic)
#$objRecordSet. Open("SELECT * FROM Table1", $objConnection, $adOpenStatic,
$adLockOptimist ic)
$toDay = Get-Date -Format yyMMdd
$fileA = "C:\SimpleList. txt"
#$objRecordSet. AddNew()
ForEach ($a in Get-Content $fileA)
{
$i = $a.split(",")
$toDay + " " + $i[0] + " " + $i[1] + " " + $i[2]
# $objRecordSet.F ields.Item("dat e").value = $toDay
# $objRecordSet.F ields.Item("fie ld01").value = $i[0]
# $objRecordSet.F ields.Item("fie ld02").value = $i[1]
# $objRecordSet.F ields.Item("fie ld03").value = $i[2]
# $objRecordSet.U pdate()
}
#$objRecordSet. Close()
#$objConnection .Close()
What am I missing?
I think you need to put $objRecordSet.A ddNew() inside the ForEach loop. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neil Chambers |
last post by:
Hi All,
I'm looking to see if it's feasible to use the SortObjectCommand
included in the Microsoft.Powershell.Commands assembly.
I have a Dictionary
Dictionary<string, intd = new Dictionary<string, int>();
d = new int;
|
by: =?Utf-8?B?VGhvbWFzIFcuIEJyb3du?= |
last post by:
1. Is there a dedicated discussion group for Windows Powershell? I couldn't
find one, but that doesn't necessarily mean there isn't :-)
2. I'm just starting in on learning to use Powershell and doing so by slowly
(very slowly) attempting to port some existing CMD and Perl scripts. I'm
blocked right now on something that should be very simple (I would think)...
I want to use SQLCMD to issue a query and parse/format the return string....
|
by: Mesan |
last post by:
Does anyone have an idea what it takes to administer DB2 through
PowerShell? I want to write some scripts to automate my common DB2
management tasks and I'd really like to be able to use PowerShell for
that scripting, but I can't find a way to run DB2 comands.
I've tried
db2cmd /w
db2cmd /w /i
db2cmd /i (this one got me the closest)
db2clpex (looked promising but not so helpfu)
|
by: Alexander Vasilevsky |
last post by:
Hi!
How to debug Powershell commandlets?
--
http://www.alvas.net - Audio tools for C# and VB.Net developers
|
by: josepharmbruster |
last post by:
I am all about using the right tool for the right purposes, which is
why I have started reading the GettingStarted guide to PowerShell. I
am curious if any other pythoneers have ventured into the world of
PowerShell. Mostly, I am interested in grabbing perspectives on the
differences noticed from those that have working experience with using
both.
I dug up one article from Google that talked about comparison but that
was about it.
| |
by: sridhard2406 |
last post by:
Hi
I didn't find a forum for powershell so i'm my query here itself.
I'm runnung a powershell script and i want to redirect the output to a xml after redirecting the output i need to search a pattern in the outfile and print on the console.
is the below is correct
filename.ps1 |out-file abc.xml | search-string -pattern "Status"
|
by: =?Utf-8?B?SmVycnk=?= |
last post by:
Hi,
I just don't get it :(
I'm using VB.NET code, within this code I want to call some Powershell code.
(To create a user mailbox in Exchange 2007). How can I run Powershell code in
vb.net?
--
Best regards,
|
by: =?Utf-8?B?YXVsZGg=?= |
last post by:
i read the MS kb:
Using Exchange Management Shell Commands With Managed Code
http://msdn.microsoft.com/en-us/library/bb332449.aspx
how ever i'm getting
"{"No Windows PowerShell Snap-ins are available for version 1."}"
exception when i try to call
PSSnapInInfo info =
rc.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapEx);
|
by: SCRIPT KEEPER |
last post by:
Hello,
I am a complete noob and just starting off with csharp so I apologize for my basic question. I am wanting to start powershell from inside a batch script and then to pass the powershell args from the batch, so from the batch I can use the name of the compiled csharp app without having to include the "call" command.
Something like "Compiled Csharp app.exe" "PowerShell Args" etc.....
Thank You for any help.
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |