locked
each line seperate RRS feed

  • Question

  • He ,

     

    i have an apllication that reads from a textfile. (the textfile is .sql)

    SELECT * FROM customers WHERE id='001
    SELECT * FROM customers WHERE id='002'
    SELECT * FROM customers WHERE id='003'

    i use streamreader the read the txt file. if i only have line the app doesnt crash but more the one line is getting stuck.

    so can i read each line seperate and procces that line.

     


    Public Class Form1
    
     Dim StreamReader As System.IO.StreamReader
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
     StreamReader = New System.IO.StreamReader("C:\d.txt") ' this is the text file where the sql statement is
    
     Dim OracleConnectionStringBuilder As New Oracle.DataAccess.Client.OracleConnectionStringBuilder
     OracleConnectionStringBuilder.DataSource = "******"
     OracleConnectionStringBuilder.UserID = "******"
     OracleConnectionStringBuilder.Password = "******"
    
     Dim OracleConnection As Oracle.DataAccess.Client.OracleConnection = New Oracle.DataAccess.Client.OracleConnection(OracleConnectionStringBuilder.ConnectionString)
    
     Dim OracleCommand As New Oracle.DataAccess.Client.OracleCommand(StreamReader.ReadLine, OracleConnection) ' this here is where you read the textfile
    
     Dim OracleDataAdapter As New Oracle.DataAccess.Client.OracleDataAdapter(OracleCommand)
    
     Dim DataTable As New DataTable
    
     OracleConnection.Open()
    
     Dim OracleDataReader As Oracle.DataAccess.Client.OracleDataReader = OracleCommand.ExecuteReader()
    
     OracleDataReader.Read()
    
     OracleDataAdapter.Fill(DataTable)
    
     Me.DataGridView1.DataSource = DataTable 'show in grid
    
     OracleConnection.Close()
    
     StreamReader.Dispose()
     StreamReader.Close()
    
     End Sub
    End Class
    
    • Edited by jackhorror Monday, June 6, 2011 12:21 PM
    Monday, June 6, 2011 11:55 AM

Answers

  • I beleive you want StreamReader.ReadToEnd if you want to return all Select's into a dataset.

    The problem you may be encountering is a lack of a delimiter. It may be appending the queries causing a parsing error.

    What is the error and what script is it trying to execute?

    Adam


    Ctrl+Z
    • Marked as answer by Liliane Teng Tuesday, June 14, 2011 9:06 AM
    Monday, June 6, 2011 12:31 PM
  • Hello jackhorror,

    Based on my understanding, the error maybe occured on the SQL sentence executed when you read more than one line from the txt file. I recommend you could set a breakpoint to check the value of StreamReader.ReadLine to ensure the format for the query string is right.

    If you have any concerns, please feel free to follow up.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Liliane Teng Tuesday, June 14, 2011 9:06 AM
    Friday, June 10, 2011 10:30 AM

All replies

  • Did you know that this is a VB forum, there is not one piece of VB in our code.

    Try this forum

    http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads


    Success
    Cor
    Monday, June 6, 2011 12:15 PM
  • I beleive you want StreamReader.ReadToEnd if you want to return all Select's into a dataset.

    The problem you may be encountering is a lack of a delimiter. It may be appending the queries causing a parsing error.

    What is the error and what script is it trying to execute?

    Adam


    Ctrl+Z
    • Marked as answer by Liliane Teng Tuesday, June 14, 2011 9:06 AM
    Monday, June 6, 2011 12:31 PM
  • Hello jackhorror,

    Based on my understanding, the error maybe occured on the SQL sentence executed when you read more than one line from the txt file. I recommend you could set a breakpoint to check the value of StreamReader.ReadLine to ensure the format for the query string is right.

    If you have any concerns, please feel free to follow up.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Liliane Teng Tuesday, June 14, 2011 9:06 AM
    Friday, June 10, 2011 10:30 AM
  • Hi jackhorror,

    What about this problem on your side now? If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 13, 2011 3:34 AM