-2

I have a table studentPhone that looks like the following:

phone      studentID
2345678      1
0562436720   1
2254754      2
0546218611   2

I want to display its data in a gridView with sqlDataSource select query as:

SELECT phone, studentID FROM studentPhone WHERE (studentID IN (1))

but the gridView display only the firstPhone of the specified studentID. How can I solve that to display all phones for a specific ID?

4

1 回答 1

0
SELECT phone, studentID FROM studentPhone WHERE (studentID = 1 )

If you want to display all the phone number of one ID in a single column then you have to write a store procedure. Example:

create table test1
( phone varchar(30),
   id int )

insert into test1(phone,id) values('2345678',1)
insert into test1(phone,id) values('0562436720',1)

Create Procedure getStudentsByID
@ID
AS
BEGIN
declare @test varchar(max)

select @test = ISNULL(@test+',','')+  test1.phone from test1 where test1.id = @ID
select @test

This will return you the comma separated list of all the phone numbers of the given ID.

于 2012-07-22T22:38:29.563 回答