English 中文(简体)
VB 阅读文本文档和执行问题
原标题:VB Scripting for reading a text file and executing query

我有以下格式的txt文件。

11SNMMMMTESTCASEJBS1961123123232YExist 

From this file I have to check the value at 33rd column, which will be Y or N. If it is N, I have to go to database and use below query

Update table XYZ set Status = Not Exist where cust_id = ** ( taken from record)

如果是Y,

Update table XYZ set Status = Exist where cust_id = ** ( taken from record)

After reading from a text file , I am trying to connect to SQLplus with a value stored in a variable and trying to update a table but I am getting below error : " Unterminated String constant Here is what code looks like, thanks to Guido for helping me out on Step 1. Can anyone please point out the error . Some error inside If & Else Part , the SQL query or connection is wrong

dim fs, txt, line, yesno , cust_id
set fs = CreateObject("Scripting.FileSystemObject")
set txt = fs.OpenTextFile("E:atchfiletestEapp3scotia1.txt", 1, false) 

  loop through all the lines
do while not txt.AtEndOfStream
    line = txt.readLine

  read the character and store it in a variable
    yesno = Mid(line, 127, 1)
    cust_id = Mid(line, 1,20)   

  execute the correct query
    if yesno = "Y" then

    set WshShell = CreateObject("WScript.Shell")
    set oEnv=WshShell.Environment("Process") 
    cmdString = "E:oracleproduct10.2.0db_1BINsqlplusw.exe -S sysman/csaadmin@convcsd

    UPDATE csa_sli_all.T_CONV_quote set HOLD_CODE =  CAQ  where quote_id =  cust_id ;
    commit;"

    Set oExec = WshShell.Exec(cmdString)

     ELSE  
    set WshShell = CreateObject("WScript.Shell")
    set oEnv=WshShell.Environment("Process") 
    cmdString = "E:oracleproduct10.2.0db_1BINsqlplusw.exe -S sysman/csaadmin@convcsd

    UPDATE csa_sli_all.T_CONV_quote set HOLD_CODE =  PVQ  where quote_id =  cust_id ;
    commit;"

    Set oExec = WshShell.Exec(cmdString)

    end if
loop
MsgBox "Press OK to close when done reading the output."
最佳回答

http://www.w3schools.com/vbscript/vbscript_ref_Functions.asp”rel=“nofollow” http://www.w3schools.com/vbscript/func_mid.asp” rel=“nofollow”

那么,你应该能够读到具体的特点位置,执行正确的询问。

文本档案中的阅读线例,从行文中储存特性,随后使用:

dim fs, txt, line, yesno

  create a file system object and open the text file
set fs = CreateObject("Scripting.FileSystemObject")
set txt = fs.OpenTextFile("C:UsersdgauravDeskto‌​pCSA -3scotia.txt", 1, false) 

  loop through all the lines
do while not txt.AtEndOfStream
    line = txt.readLine

      read the character and store it in a variable
    yesno = Mid(line, 33, 1)

      execute the correct query
    if yesno = "Y" then
        WScript.Echo "Yes"
    else
        WScript.Echo "No"
    end if
loop
问题回答

暂无回答




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签