| | |
Query and text file
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 2
Hope this code can help you.
Dim _streamWriter As System.IO.StreamWriter
Dim _fileName As String = "fileName.txt"
If _table IsNot Nothing AndAlso _table.Rows.Count > 0 Then
_streamWriter = New System.IO.StreamWriter(_fileName)
For Each _row As DataSet1.EmployeesRow In _table.Rows
Dim _string As String = ""
For Each _column As DataColumn In _table.Columns
_string += _row.Item(_column.ColumnName).ToString + Chr(Keys.Tab)
Next
_streamWriter.WriteLine(_string)
Next
_streamWriter.Close()
End If
Dim _streamWriter As System.IO.StreamWriter
Dim _fileName As String = "fileName.txt"
If _table IsNot Nothing AndAlso _table.Rows.Count > 0 Then
_streamWriter = New System.IO.StreamWriter(_fileName)
For Each _row As DataSet1.EmployeesRow In _table.Rows
Dim _string As String = ""
For Each _column As DataColumn In _table.Columns
_string += _row.Item(_column.ColumnName).ToString + Chr(Keys.Tab)
Next
_streamWriter.WriteLine(_string)
Next
_streamWriter.Close()
End If
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
could you give a more specific example on how to retrieve from the table example employee table
name id add dob
JOHN 23 street 1 23/07/1980
TOMY 20 street 4 11/03/1979
and in the text file i want the record to be exectly the same
JOHN 23 street1 23/07/1980
TOMY 20 street 4 11/03/1979
how should i do this?
thanks
name id add dob
JOHN 23 street 1 23/07/1980
TOMY 20 street 4 11/03/1979
and in the text file i want the record to be exectly the same
JOHN 23 street1 23/07/1980
TOMY 20 street 4 11/03/1979
how should i do this?
thanks
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 2
Hello.
I did not understand Have you got table (your employee datatable)?
You must to take data to dataset from database.
For example you have got table in the dataset. The name of this table is "Employee".
I am sure next code will give you result.
dim _streamWriter as StreamWriter
dim _table as DataTable = _dataSet.Tables("Employee")
'Check table. If table has is not nothing and has any records you will write rows to text file.
if _table isnot nothing andalso _table.Rows.Count > 0 then
_streamWriter = New System.IO.StreamWriter(myFileName)
for each _row as DataRow in _table.Rows
Dim _name as String = _row.Item("Name")
Dim _id as String = _row.Item("ID").ToString()
Dim _add as string = _row.Item("Add")
Dim _dob as string = Format(_row.Item("dob"), "dd/MM/yyyy")
_streamWriter.WriteLine(_Name & " " & _id & " " & _add & " " & _dob)
Next
_streamWriter.Close()
end if
I did not understand Have you got table (your employee datatable)?
You must to take data to dataset from database.
For example you have got table in the dataset. The name of this table is "Employee".
I am sure next code will give you result.
dim _streamWriter as StreamWriter
dim _table as DataTable = _dataSet.Tables("Employee")
'Check table. If table has is not nothing and has any records you will write rows to text file.
if _table isnot nothing andalso _table.Rows.Count > 0 then
_streamWriter = New System.IO.StreamWriter(myFileName)
for each _row as DataRow in _table.Rows
Dim _name as String = _row.Item("Name")
Dim _id as String = _row.Item("ID").ToString()
Dim _add as string = _row.Item("Add")
Dim _dob as string = Format(_row.Item("dob"), "dd/MM/yyyy")
_streamWriter.WriteLine(_Name & " " & _id & " " & _add & " " & _dob)
Next
_streamWriter.Close()
end if
•
•
•
•
could you give a more specific example on how to retrieve from the table example employee table
name id add dob
JOHN 23 street 1 23/07/1980
TOMY 20 street 4 11/03/1979
and in the text file i want the record to be exectly the same
JOHN 23 street1 23/07/1980
TOMY 20 street 4 11/03/1979
how should i do this?
thanks
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
thanks for the advise.
i understand that the data inserted in the text file is seperated by " " right?
how about if i want to insert the data from the text file into another table? how do i ensure that the data inserted correctly into another table according to the to the seperation of the " " in the text file?
JOHN 23 street 1 23/07/1980
if i get the seperation by " " the street 1 suppose to be one value will become 2 value as street will be seperated by " " then 1 in the txt file. how should i do this?
i understand that the data inserted in the text file is seperated by " " right?
how about if i want to insert the data from the text file into another table? how do i ensure that the data inserted correctly into another table according to the to the seperation of the " " in the text file?
JOHN 23 street 1 23/07/1980
if i get the seperation by " " the street 1 suppose to be one value will become 2 value as street will be seperated by " " then 1 in the txt file. how should i do this?
![]() |
Similar Threads
- query table to import text file to excel is slow (Visual Basic 4 / 5 / 6)
- Query a Text File (Java)
- Reading through lines of text file sequencially (Shell Scripting)
- MySql commands in a text file (PHP)
- read from database and writing the contents into a text file (C)
- read text file (C)
Other Threads in the VB.NET Forum
- Previous Thread: how to read this file
- Next Thread: Exporting to PDF in VS2005
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





