?
Solved

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.

Posted on 2011-10-14
6
Medium Priority
?
200 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:jjc9809
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36968926
Is the grid populated with a datatable?
0
 

Author Comment

by:jjc9809
ID: 36969042
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36969153
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jjc9809
ID: 36969295
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36969440
That was for demonstration purposes. Do with these values whatever you want to do. Write them to a text file.
0
 

Author Closing Comment

by:jjc9809
ID: 36980666
Very good
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question