[Solved] How to export csv file with specific name?


Your switch case is incorrect, right now you’re making a mix of switch case and if statements, but your switch case will always go to case 9 and you don’t actually need a switch case on integers. You need to change it to something like this:

    string o = saiNathHospitalDataSet.Tables["PatientTable"].Rows[i]["WARD NAME"];

    const string a = "GENERAL WARD (FEMALE)";
    const string b = "GENERAL WARD (MALE)";
    const string c = "RECOVERY";
    const string d = "SEMI DELUXE 02";
    const string e = "SEMI DELUXE 05";
    const string f = "SEMI DELUXE 06";
    const string g = "ICU";
    const string h = "SEMI SPECIAL 03";
    const string j = "SEMI SPECIAL 01";

    switch (o)
    {
        case (a):
            //Do something
            break;
        case (b):
            //Do something
            break;
        default:
            //Do something
            break;
    }

Edit: If you want to export a file per patient for each of your wards, you will have to change your foreach loop of your export method to something like this:

foreach (var row in rows)
{
    using (var sw = new StreamWriter(txtreceive.Text + "\\" + "Some variable to identify different patients" + filename))
    {
        sw.WriteLine(header);
        sw.WriteLine(row);
    }
}

Assuming each row represents a patient, you need to create a file per row.

1

solved How to export csv file with specific name?