I need to write out data from a Gridview by Row and Column to a TextFile using VB. The TextFile will be in different positions which I will use the String Builder Class.

Hi everyone,

I am looking for sample code to write out data from a Gridview Row and Column to a TextFile.  Data will be entered line by line into a Sql  2005 Database by row and column.  I can have up to 100 rows with 14 columns.  The textfile will be written out with different positions using a String Builder Class with no concatanations.  Say I have a transaction with 100 rows and 14 columns.  I would pull the transaction by a Data Posted Parameter.  My Gridview would load all 100 lines with 14 columns.  I need to be able to reference each row and column by name so the data will be written out in the correct position.  Each row could have fields with different positions in the textfile.

My question is this.  How do I reference each piece of data row and column.  Say Row1 Column1, Row1 Column2 and so on.  I need to know what is in each field.

Any sample data writing out 3 columns with 3 rows would help me.

jjc9809
jjc9809Asked:
Who is Participating?
 
CodeCruiserCommented:
If you are using a datatable, you can loop through it using the following syntax

For i As Integer = 0 to DataTable1.Rows.Count - 1
   msgbox DataTable1.Rows(i).Item(0) & ", " & DataTable1.Rows(i).Item(1)  'Only deals with two columns
Next
0
 
CodeCruiserCommented:
Is the grid populated with a datatable?
0
 
jjc9809Author Commented:
Yes a data table would be correct.  The SQL Table holding data would be called JV Table.  I know how to use the string writer and so forth, but I just need to know hwo to reference my 100 rows and 14 columns with data each row and column.  Becuase I would use the StringBuilder Class to Append.  Say column 1 is called Line.  I would Reference using the String Builder as sb.Append(Line1.Text) for example.  I would then have sb.Append(Sline12) or 12 spaces and have sb.Append("JV").  The text file would write out like this for example:

01            JV

 
I hope I made sense with this.



jjc9809
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
jjc9809Author Commented:
CodeCruiser,

I would refer to Row1, Column1 and Row1, Column2  as DataTable1.Rows(i).Item(0) & "," & DataTable1.Rows(i).Item(1)

As the computer loops through the For Next Loop, (i) would start at 0 and increment each time through the loop and the Item (0) would be your first column and Item (1) would be your second column and so on.  Now, you would not have a msgbox on every line like this: msgbox DataTable1.Rows(i).Item(0) & ", " & DataTable1.Rows(i).Item(1)  would you?  

jjc9809
0
 
CodeCruiserCommented:
That was for demonstration purposes. Do with these values whatever you want to do. Write them to a text file.
0
 
jjc9809Author Commented:
Very good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.