how to insert a text in a top of the text file with out deleteing previous text

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
am using vb2008 and sql serverDim sqlstr As String = "SELECT * FROM TBL_DOORCOLLECTION_IP"

Dim da As SqlDataAdapter

Dim ds As New DataSet

da = New SqlDataAdapter(sqlstr, con)


da.Fill(ds)

Dim dt As DataTable = ds.Tables(0)
DataGridView1.DataSource = dt

------------------------------------------------------------------

Building the CSV from the table



Dim CSVdelimiter As String = ","



Be aware that this can be in every culture different

In the EU it is "";"" however to keep it with its name

comma seperated I have showed it as sample with the comma

Dim sb As New System.Text.StringBuilder()

Dim Names(dt.Columns.Count) As String

sb.Append("")


For i As Integer = 0 To dt.Columns.Count - 2

sb.Append(dt.Columns(i).ColumnName)

sb.Append(CSVdelimiter)

Next

sb.Append(dt.Columns(dt.Columns.Count - 1).ColumnName)

sb.Append("" & vbCrLf)

For Each drv As DataRowView In dt.DefaultView

sb.Append("")


For i As Integer = 0 To dt.Columns.Count - 2

sb.Append(drv.Row.ItemArray(i).ToString)

sb.Append(CSVdelimiter)

Next

sb.Append(drv.Row.ItemArray(dt.Columns.Count - 1).ToString)

sb.Append("" & vbCrLf)

Next

Dim sr As New IO.StreamWriter("C:my.txt")

sr.Write(sb.ToString)

sr.Close()

this is my code for write a text into .txt file
i want to write "title (its in another table )" in same text file

View the full article
 
Back
Top