Good day, I am new in programing (still a student). I whant to write a c# program using winform, which will populate data from an external text file(as a array) into a textarea in the form, to check if each data in the textarea is present anywhere in a specified column of as many excel workbook as specified in the form.

Please how do i go about this. Thanks

Dani AI

Generated

A concise, practical plan that complements 's description and 's OleDb/DataTable suggestion.

A workable workflow:

  • Load and normalize the employee-ID list coming from the text area or file (split on lines, trim whitespace, drop empty entries, normalize casing and leading zeros). Keep them in a HashSet for uniqueness and O(1) lookups.
  • For each workbook listed in the form, read the sheet that contains payroll data with a library suited to the file type (.xls vs .xlsx). Detect the header row by scanning the first row for a header that contains the word "house" (case-insensitive, tolerant of punctuation). Collect the IDs that appear in that House-allowance column and whose allowance cell is non-empty.
  • After processing every workbook, compute the set difference: IDs in the input list that never appeared in any House-allowance column are the unpaid employees. Export that difference to a grid, CSV, or print routine.

Key pitfalls and fixes:

  • Excel stores values inconsistently: numeric IDs may be stored as numbers while the text file has strings. Coerce cell values to string, trim, and normalize before comparing.
  • Empty-looking cells can contain spaces or nonprinting characters; treat whitespace-only as empty.
  • Sheet names, merged cells, and hidden rows can hide data—scan the actual used range rather than assuming fixed row counts.
  • If using OleDb, watch driver/bitness issues and HDR/IMEX behavior; alternative libraries avoid those problems.

Libraries and references:

Recommended Answers

All 5 Replies

Waht do you mean textarea (data in textarea? what is this? Do you mean TextBox controls?
If so you can check:

 bool bCheckTextBoxes = this.Controls.OfType<TextBox>().Any(a => string.IsNullOrEmpty(a.Text));
if (!bCheckTextBoxes)
{
     MessageBox.Show("Not all textBoxes are fulfiled.");
}

And which specific column? I am not sure what do you mean. Can you be please more exact?
thx

Thanks Bonca. The real sinerio is, i hav a payroll where staff salary details are stored, wen i staff is payed the different alowancies are enter in different columns of a worksheet and i also hav the employee ID typed in a text file. each department has a workbook for their records. now i want to check which employee has not been payed house allowance by checkin the empID file against the House allowance column and printing them out. Thanks

So you work witj excel file?
Next time be more precise about the issue, ok?

So in your file (and in some worksheet) you have columns EmpID, House allowence, and others.
So you wanna check which employee doesnt have any record?
You can use OLEDB provider, and fill DataTable, and check

'using System.Data;
'using System.Data.OleDb;

'in your method:
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=Excel 8.0")
Dim da As New OleDbDataAdapter("SELECT * FROM  YourSheetName", con)
Dim dt As New DataTable()
da.Fill(dt)

'create a list, to put all employee IDs that didnt pay House allowance:
Dim _ids As List(Of String) = table.AsEnumerable().Where(Function(w) DirectCast(w("house allowence"), String) = "").[Select](Function(s) DirectCast(s("id"), String)).ToList()

'
'this is my whole example, so you can see what I mean!
'the result is 2 and 4:
Dim table As New DataTable()
table.Columns.Add("id", GetType(String))
table.Columns.Add("house allowence", GetType(String))
table.Rows.Add("1", "34")
table.Rows.Add("2", "")
table.Rows.Add("3", "12")
table.Rows.Add("4", "")
Dim ids As List(Of String) = table.AsEnumerable().Where(Function(w) DirectCast(w("house allowence"), String) = "").[Select](Function(s) DirectCast(s("id"), String)).ToList()

Oh Bunca, You hav done alot for so far, I really appreciate, But i can't use vb at all i use c#. Please

Sorry, here is C# version:

//using System.Data;
//using System.Data.OleDb;
//in your method:

{
    OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Book1.xls;Extended Properties=Excel 8.0");
    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM  YourSheetName", con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    //create a list, to put all employee IDs that didnt pay House allowance:
    List<string> _ids = table.AsEnumerable().Where(w => string.IsNullOrEmpty((string)w["house allowence"])).Select(s => (string)s["id"]).ToList();
    //
    //this is my whole example, so you can see what I mean!
    //the result is 2 and 4:
    DataTable table = new DataTable();
    table.Columns.Add("id", typeof(string));
    table.Columns.Add("house allowence", typeof(string));
    table.Rows.Add("1", "34");
    table.Rows.Add("2", "");
    table.Rows.Add("3", "12");
    table.Rows.Add("4", "");
    List<string> ids = table.AsEnumerable().Where(w => string.IsNullOrEmpty((string)w["house allowence"])).Select(s => (string)s["id"]).ToList();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.