Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim objReader As StreamReader
        Dim objWriter As StreamWriter
        Dim i As Integer = 0
        Dim LineIn As String
        
        Try
           
          
            For i = 0 To mFileName.Length - 1
                objReader = File.OpenText(mFileName(i))
                objWriter = New IO.StreamWriter(FilePATH1 & "\" & TextBox1.Text & ".sql", True)
                'here it will write all files in Test.sql

                While objReader.Peek <> -1
                    LineIn = objReader.ReadLine()
                    objWriter.Write(LineIn & vbNewLine)
                End While
                objWriter.WriteLine("Go")
                objWriter.Close()


            Next
           


        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try




now what my problem if i execute again duplicate data is going to append to destination file...please help me..thanks
Posted
Updated 7-Nov-11 19:41pm
v2

1 solution

First write your file blank. Then append the text.
VB
Dim objReader As StreamReader
Dim objWriter As StreamWriter
Dim i As Integer = 0
Dim LineIn As String

Try
  objWriter = New IO.StreamWriter(FilePATH1 & "\" & TextBox1.Text & ".sql")
  objWriter.WriteLine("")
  objWriter.Close()
  For i = 0 To mFileName.Length - 1
    objReader = File.OpenText(mFileName(i)) 'here it will write all files in Test.sql
    objWriter = New IO.StreamWriter(FilePATH1 & "\" & TextBox1.Text & ".sql", true)
      While objReader.Peek <> -1
        LineIn = objReader.ReadLine()
        objWriter.Write(LineIn & vbNewLine)
      End While
    objWriter.WriteLine("Go")
    objWriter.Close()
  Next
Catch ex As Exception
  MessageBox.Show(ex.Message)
End Try
 
Share this answer
 
v4
Comments
s.chiranjeevi 8-Nov-11 2:06am    
hai patel..thanks for response..
actually f1.sql contains hai,f2.sql contains bye..if my destination is chiru.sql then result is hai go bye go..later if i have another file goodmor then i am getting hai go bye go hai go bye go goood morning go..i dont need this...i need to append good morning to chiru.sql
Prerak Patel 8-Nov-11 2:22am    
I got that. Did you try what I suggested? It makes the file blank first and then adds all. Which results in hai go bye go goood morning go in chiru.sql as you say. See I am highlighting the change in answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900