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

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.