none
Using info from table accessed by LINQ RRS feed

  • Question

  • Hi:

    I have a table 'Patients' in a dataset 'BillingData'. I'd like to use LINQ to get the patient's name based on the unique Record Number. This code seems to allow me to get to the table. The problem now is what should the last line look like so I can use it in the label text? If I use 'pt.Firstname', I'm told 'pt does not exist in this context'. On the other hand, using 'pat.Firstname' I'm told 'System.data.enumerableRowCollection<AnonymousType#1>does not contain a definition for 'Firstname'. Thanks for any and all help.

    var pat = from ptin billingDataSet.Patients

    where pt.RecNum == (Int64)rNumber

    select new { pt.Firstname, pt.Lastname };

    this.lblFN.Text = pat.Firstname;


    JohnCFowler
    Thursday, September 22, 2011 12:47 AM

Answers

  • Hi John,

    Welcome!

    You should first to retrieve the datatable from the dataset:

            static void Main(string[] args)
            {
               DataSet1TableAdapters.EmployeesTableAdapter adapter= new DataSet1TableAdapters.EmployeesTableAdapter();       
                DataSet1.EmployeesDataTable employee= new DataSet1.EmployeesDataTable();
                     adapter.Fill(employee);
                     var test = from pt in employee.AsEnumerable() where pt.Name.Length > 2 select new { pt.Name, pt.EmployeeId };
                     var name = test.First().Name;
            }
        }
    

    // your Pat is a collection, so you shoulde use .First() method to get the first record in the collection.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by BoovendanM Friday, September 30, 2011 6:29 AM
    • Marked as answer by Alan_chenModerator Monday, October 3, 2011 7:32 AM
    Thursday, September 22, 2011 3:06 AM
    Moderator

All replies

  • Hi John,

    Welcome!

    You should first to retrieve the datatable from the dataset:

            static void Main(string[] args)
            {
               DataSet1TableAdapters.EmployeesTableAdapter adapter= new DataSet1TableAdapters.EmployeesTableAdapter();       
                DataSet1.EmployeesDataTable employee= new DataSet1.EmployeesDataTable();
                     adapter.Fill(employee);
                     var test = from pt in employee.AsEnumerable() where pt.Name.Length > 2 select new { pt.Name, pt.EmployeeId };
                     var name = test.First().Name;
            }
        }
    

    // your Pat is a collection, so you shoulde use .First() method to get the first record in the collection.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by BoovendanM Friday, September 30, 2011 6:29 AM
    • Marked as answer by Alan_chenModerator Monday, October 3, 2011 7:32 AM
    Thursday, September 22, 2011 3:06 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day. 


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 26, 2011 3:21 AM
    Moderator