Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Read txt file and compare to database

Reply
 
Old 09-10-2008   #1 (permalink)
Meat


 
 

Read txt file and compare to database

Hi,

I want to read a txt file and compare each line with data in a SQL database.
The connection to the SQL server and the databases are OK. The script is
running well exept that the strServerPlage variable is always stuck with the
same value :

set objFile = CreateObject("Scripting.FileSystemObject")
set TheFile = objFile.GetFile(srcFile)
set objServer = objFile.OpenTextFile(TheFile, ForReading, true)
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet1 = CreateObject("ADODB.Recordset")
Set objRecordSet2 = CreateObject("ADODB.Recordset")
Set i = 0

objConnection.Open "Provider=SQLOLEDB;Data Source=Server1;Initial
Catalog=Cat1;User ID=IDnum;Password=Pass"
If objConnection.State <> 1 Then
functionWriteLog "10", "No connection"
objConnection.Close
EndScript
End if

objRecordSet1.Open "SELECT * FROM dbo.table1", objConnection,
adOpenStatic, adLockOptimistic
objRecordSet2.Open "SELECT * FROM dbo.table2", objConnection,
adOpenStatic, adLockOptimistic

objRecordSet1.MoveFirst
objRecordSet2.MoveFirst

Do While Not objServer.AtEndOfStream
strSearching = objServer.ReadLine
VarArray = Split(strSearching, ";", -1, 1)
strServerName = CStr(VarArray(0))
strServerPlage = CStr(VarArray(2))

Select Case strServerPlage

Case "String 1"
strCompTxt = "Result 1"

Case "String 2"
strCompTxt = "Result 2"

Case "String 3"
strCompTxt = "Result 3"

Case "String 4"
strCompTxt = "Result 4"

Case Else
strCompTxt = "NO RESULT"

End select

Do Until objRecordSet1.EOF = true
If strServerName = objRecordSet1.Fields("ServerName") Then
strMachineID = objRecordSet1.Fields("Machine")
Exit do
Else
objRecordSet1.MoveNext
End if
Loop

If strMachineID = "" Then
i = i + 1
Else
Do Until objRecordSet2.EOF = true
If CStr(objRecordSet2.Fields("Machine")) = CStr(strMachineID) Then
strCompInv = CStr(objRecordSet2.Fields("Plage"))

If strCompInv = "" Then
functionWriteLog "No entry for this server : ", strServerName
Exit do
Else
strCompInv = objRecordSet2.Fields("Plage")
End if

strCompResult = functionStrComp(strCompInv, strCompTxt)

If strCompResult = 1 Then
functionWriteLog "Difference : ", strServerName
Exit do
End if
Else
objRecordSet2.MoveNext
End if
Loop
End if

Loop

objServer.Close
objRecordSet1.Close
objRecordSet2.Close
objConnection.Close

I want to know how can I move to the next line in the text file so I can
read it and so on until the end of the file.

Thank you.

My System SpecsSystem Spec
Old 09-10-2008   #2 (permalink)
Meat


 
 

RE: Read txt file and compare to database

I'm sorry, the variable strCompInv is always the same.

Thank you.

"Meat" wrote:
Quote:

> Hi,
>
> I want to read a txt file and compare each line with data in a SQL database.
> The connection to the SQL server and the databases are OK. The script is
> running well exept that the strServerPlage variable is always stuck with the
> same value :
>
> set objFile = CreateObject("Scripting.FileSystemObject")
> set TheFile = objFile.GetFile(srcFile)
> set objServer = objFile.OpenTextFile(TheFile, ForReading, true)
> Set objConnection = CreateObject("ADODB.Connection")
> Set objRecordSet1 = CreateObject("ADODB.Recordset")
> Set objRecordSet2 = CreateObject("ADODB.Recordset")
> Set i = 0
>
> objConnection.Open "Provider=SQLOLEDB;Data Source=Server1;Initial
> Catalog=Cat1;User ID=IDnum;Password=Pass"
> If objConnection.State <> 1 Then
> functionWriteLog "10", "No connection"
> objConnection.Close
> EndScript
> End if
>
> objRecordSet1.Open "SELECT * FROM dbo.table1", objConnection,
> adOpenStatic, adLockOptimistic
> objRecordSet2.Open "SELECT * FROM dbo.table2", objConnection,
> adOpenStatic, adLockOptimistic
>
> objRecordSet1.MoveFirst
> objRecordSet2.MoveFirst
>
> Do While Not objServer.AtEndOfStream
> strSearching = objServer.ReadLine
> VarArray = Split(strSearching, ";", -1, 1)
> strServerName = CStr(VarArray(0))
> strServerPlage = CStr(VarArray(2))
>
> Select Case strServerPlage
>
> Case "String 1"
> strCompTxt = "Result 1"
>
> Case "String 2"
> strCompTxt = "Result 2"
>
> Case "String 3"
> strCompTxt = "Result 3"
>
> Case "String 4"
> strCompTxt = "Result 4"
>
> Case Else
> strCompTxt = "NO RESULT"
>
> End select
>
> Do Until objRecordSet1.EOF = true
> If strServerName = objRecordSet1.Fields("ServerName") Then
> strMachineID = objRecordSet1.Fields("Machine")
> Exit do
> Else
> objRecordSet1.MoveNext
> End if
> Loop
>
> If strMachineID = "" Then
> i = i + 1
> Else
> Do Until objRecordSet2.EOF = true
> If CStr(objRecordSet2.Fields("Machine")) = CStr(strMachineID) Then
> strCompInv = CStr(objRecordSet2.Fields("Plage"))
>
> If strCompInv = "" Then
> functionWriteLog "No entry for this server : ", strServerName
> Exit do
> Else
> strCompInv = objRecordSet2.Fields("Plage")
> End if
>
> strCompResult = functionStrComp(strCompInv, strCompTxt)
>
> If strCompResult = 1 Then
> functionWriteLog "Difference : ", strServerName
> Exit do
> End if
> Else
> objRecordSet2.MoveNext
> End if
> Loop
> End if
>
> Loop
>
> objServer.Close
> objRecordSet1.Close
> objRecordSet2.Close
> objConnection.Close
>
> I want to know how can I move to the next line in the text file so I can
> read it and so on until the end of the file.
>
> Thank you.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can VBScript read foxpro 2.6 database? VB Script
How to read sql server database properties PowerShell
locating a database file Vista file management
interesting read> media player database Vista General
Text File Compare PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46