Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3673210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:42:17+00:00 2026-05-19T02:42:17+00:00

i have a datatable: var dt = new DataTable(); dt.Columns.Add(new DataColumn(specimen, typeof(string))); dt.Columns.Add(new DataColumn(batch,

  • 0

i have a datatable:

        var dt = new DataTable();
        dt.Columns.Add(new DataColumn("specimen", typeof(string)));
        dt.Columns.Add(new DataColumn("batch", typeof(string)));
        dt.Columns.Add(new DataColumn("position", typeof(string)));

the data looks something like this inside of it:

Spec. ID    Batch/Pos.  position
AA00721 16785   3
AA00722 16785   2
AA00734 16785   3
AA00735 16860   6
AA00737 16862   4
AA00738 16860   7
AA00739 16863   5
AA00740 16860   9
AA00741 16861   7
AA00742 16861   0
AA00743 16861   5

for each unique batch, i need to create a file with all the specIDs and positions.

for example file 16785.txt would look like this:

AA00721 3
AA00722 2
AA00734 3

how would i loop through this datatable to create separate files>? please assume that the batch numbers are not sorted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:42:17+00:00Added an answer on May 19, 2026 at 2:42 am

    If you would like to utilize a LINQ method, I would group your data on the batch and then just iterate through the groups.

    var groupedData = from DataRow row in dt.Rows
                        let specimen = row["specimen"].ToString()
                        let batch = row["batch"].ToString()
                        let position = row["position"].ToString()
                        group new { specimen, position } by batch;
    
    foreach (var dataGroup in groupedData)
    {
        string fileName = string.Format(@"C:\Temp\{0}.txt", dataGroup.Key); // construct filename based on batch?
        using (StreamWriter writer = new StreamWriter(fileName))
        {
            foreach (var item in dataGroup)
            {
                writer.WriteLine("{0}\t{1}", item.specimen, item.position);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some C# code that looks something like this System.Data.DataRow row; var table
I have to List of Data : List<string[]> dataRow = new List<string[]>(); every string[]
I have a DataTable with data in a string column. Values: 1 { 2
I have a LINQ query to a DataTable : var list = from row
I have datatable with column name tag and 100 rows of data.I need to
I have a DataTable with 3 columns (a,b,c) and a docx file with the
I have a DataTable object. Every column is of type string. Using LINQ, how
I have a datatable like public DataTable functiongettable() { DataTable dt = new DataTable();
I have a DataTable that I manually created and loaded with data using C#.
I have a DataTable as a data source of a GridView. I'm adding a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.