|
-
Dec 14th, 2008, 11:14 PM
#1
Thread Starter
Addicted Member
[02/03] fixed lenght file
Hi gurus
I have a little proyect to do, I need to query a sql database and get some information, I have this done using the datatable, now I need to get that information, loop through the datatable and write to the file every field that is on every row on the datatable.
Here is where I need help, how do I loop through the datatale to get the fields.
Thanks
-
Dec 14th, 2008, 11:38 PM
#2
Re: [02/03] fixed lenght file
You'd probably want to refine this a little but it gives a pretty good idea:
vb.net Code:
Dim upperBound As Integer = table.Columns.Count - 1 Dim writer As New IO.StreamWriter("file path here") For Each row As DataRow In table.Rows For columnIndex As Integer = 0 To upperBound If columnIndex > 0 Then writer.Write(",") End If writer.Write(row(columnIndex).ToString()) Next writer.WriteLine() Next writer.Close()
-
Dec 15th, 2008, 07:34 AM
#3
Thread Starter
Addicted Member
Re: [02/03] fixed lenght file
Thanks big J.
Is there a way that I can bring the filed name out of the row, something like
Code:
for each row in datatable
string1=row("firstname")
string2=row("lastname")
string3=row("DOB")
do some writting to the file
next
I still need to work on those values once the query is brought to the datatable or dataset.
Thanks a bunch for the help.
-
Dec 15th, 2008, 07:45 AM
#4
Re: [02/03] fixed lenght file
How about this one ?
Code:
Dim writer As New IO.StreamWriter("file path here")
for each row in datatable
string1=row("firstname")
string2=row("lastname")
string3=row("DOB")
' do some writting to the file
writer.WriteLine(String.Format("{0}{1}{2}", string1, string2, string3))
next
Please mark you thread resolved using the Thread Tools as shown
-
Dec 15th, 2008, 08:57 AM
#5
Thread Starter
Addicted Member
Re: [02/03] fixed lenght file
thanks D.
so I CAN do this!!!!
1. come with the query
2. once the query's result is store on a datatable I can go and get the values of every fields on each row buy just bring the field name into the string and do some cool staff before writting to the file?
Now I have another question
datatable
firstname lastname DOB
Jack moore 3/3/2208
mike janson 3/3/2209
can I do this
string1=row("dob")
string2=row("firstname")
string3=Row(lastname")
and it will bring the right values
Thanks again
-
Dec 16th, 2008, 12:12 AM
#6
Re: [02/03] fixed lenght file
 Originally Posted by GUARO
thanks D.
string1=row("dob")
string2=row("firstname")
string3=Row(lastname")
and it will bring the right values
Thanks again
yes it will
Please mark you thread resolved using the Thread Tools as shown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|