简体   繁体   中英

Choose specific value to show in a textbox from a SQL View

I am pretty new to programming in general so I am going to bagger this question in a thousand ways at least and I am sorry ahead of item. I have a view of a couple tables I created in a SQL database. They have foreign key relationships and a couple one to many tables. I have an employee table and a phone number table that are linked.

All employees have at least 1 number some employees have 2 or more numbers listed and I want to be able to choose which number of the few to show in a textbox or even in a couple text boxes. If I do textbox.text = employee.PhoneNumber (subsonic) then it only gives me the first number. Can someone point me to a guide or explain to me how I would choose which of the said values I would like to show in that textbox?

Thank you very much for any assistance you can give.

ps When I test the veiw in sql I get the same employee listed multiple times because of the different numbers so I know the data is there I just dont know how to access the other 2 phone numbers in the list.

i have zero experience with subsonic but it does look strange that you can access a non scalar value like this (employee to phone number is a 1-n or mn relation so employee objects should NOT have a scalar field containing a phone number, but a collection of 0 or more phone number objects) if your employee objects have a scalar phone number object i would recommend to check the relation

//edit

so your VIEW contains something like this:

employee + phone  
John Doe | 123  
John Doe | 456  
Jane Doe | 789

lets say that result is an enumeration of some type T containing the values as properties or fields with the given names ...

so you have

IEnumerable< T > data; // initialized somewhere else
IEnumerable< IGrouping<WhateverTypeEmployeeIs,T>> tmp = from x in data group x by x.employee;
var employees = from x in tmp select new { employee = x.Key, phoneNumbers = x.Select(y => y.phone).ToArray() };

employees will contain an IEnumerable< > of a new anonymous type with 2 properties:
employee - containing your employee
phoneNumbers - containing an array of phone numbers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM