![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||