how to replace array(0) names in txt file ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi all

<span style="line-height:115%; font-family:Times New Roman,serif; font-size:12pt I have txt file and I updated the txt from different sources

<span style="line-height:115%; font-family:Times New Roman,serif; font-size:12pt For example:
<span style="line-height:115%; font-family:Times New Roman,serif; font-size:12pt This the main file
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt <ti>,<date>,<o>,<h>,<l>,<cl>,<vo><br/>
si,20111102,27.3,28.5,27.2,28,224126<br/>
si,20111102,28.3,29.5,24.2,28,224126<br/>
bbb,20111112,28.1,28.2,27.6,28.2,237681<br/>
sss,20111112,27.144,28.222,24.644,25.244,237681<br/>
sss,20111113,27.9,28.4,27.9,28.4,69486<br/>
fff,20111113,24.944,25.6643,23.2300,24.4330,69486<br/>
fff,20111102,9.9,9.95,9.8,9.9,639546<br/>
trtr,20111102,9.8534,9.9524,9.452,9.4500,639546<br/>
trtr,20111112,10.25,10.35,10.05,10.3,3006550<br/>
fa,20111112,9.2500,10.3545,8.0500,9.300,3006550<br/>
fa,20111113,10.3,10.3,10.15,10.25,1053258<br/>
<br/>

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt I download the txt file to update the main file but some names of first string change like so:
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt From

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt bbb, become as bbrw,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt trtr,<span>
become as trtw,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt And most remain as it is
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt Another download of data using number as
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt bbb, become as 1432,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt sss, become as 6543,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt fff, become as 2312,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt trtr, become as 9432,
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt So what is the best way to fix the update?

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt I create table and I load the first array and


<pre class="prettyprint lang-vb Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
If marketseting.SelectedItem <> "SELECT" Then
Dim cmd As OleDbCommand

Dim connStr = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:TSOSM" & marketseting.SelectedItem.ToString() & "" & marketseting.SelectedItem.ToString() & ".mdb;Persist Security Info=False;")
Dim sqlText = "INSERT INTO [" & marketseting.Text & "definition" & "] (CompName) VALUES (?)"
Dim inputFile = "C:test.txt"

Using conn As New OleDb.OleDbConnection(connStr)
Dim cmd As New OleDb.OleDbCommand(sqlText, conn)

Dim fs As IO.StreamReader = Nothing
Try
fs = New IO.StreamReader(inputFile)
Catch ex As Exception
MsgBox("Could not open file: " & ex.Message)
End Try

fs.ReadLine() discard line with headers

While Not fs.EndOfStream
Dim line = fs.ReadLine()
Dim arrayForTheLine = line.Split(","c)

If arrayForTheLine.Count > 0 Then
MsgBox("Wrong number of items in " & line)
Else
Dim strti = arrayForTheLine(0)


cmd.Parameters.Clear()

cmd.Parameters.AddWithValue("@CompName", strti)


Try
conn.Open()
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MsgBox("OleDbException: " & ex.Message)
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
Finally
conn.Close()
End Try

End If

End While

fs.Close()

End Using

MessageBox.Show("done")


End If

End Sub[/code]
<br/>
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt And I try to use datagridview manipulate the data like:
<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt CompName<span>
name2 <span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt <span> <span> <span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt namebynumber
<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt <span> <span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt <span> <span> Bbb
<span> bbrw<span>
1432

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt And after that I will update the table when the update done I will replace the array (0) in test.txt file

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt But the problem
datagridview <span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt
will work with one database
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt And what I have is: three database in three folders
<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt C:TSOSM folder that contain three folders

<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt That listed in combobox
<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt Each folder has one database contain two tables

<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt One that I will use to replace the name of the array (0) in test.txt file

<span style="color:#a31515; line-height:115%; font-family:Consolas; font-size:9.5pt Called ["<span style="line-height:115%; font-family:Consolas; font-size:9.5pt & marketseting.Text &
<span style="color:#a31515 "definition" & <span style="color:#a31515
"] in the entire three database.

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt So

<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt 1-what is the best way to fix the update by replace the new name by old name in the test.txt file?
<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt 2- Is there a way to use datagridview for three tables every table in different database to update them based on the value of the combo box ?

thank you<span style="color:#666666; line-height:115%; font-family:Segoe UI,sans-serif; font-size:10.5pt
<br/>

View the full article
 
Back
Top