Click here to Skip to main content
15,033,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
SqlDataReader xreader = xCmd.ExecuteReader();
while (xreader.Read())
{
 return xreader[0].ToString();
}

//ajax function
$.ajax({
            type: "POST",
            url: "Main.aspx/GetDataID",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                GetDataP(result.d);
            }

        });



problem is that when i return value with loop .... loop is run only one time and after one time return loop is break ..... please give me a solution
Posted
Updated 16-Jul-13 3:10am
v2
Comments
ZurdoDev 16-Jul-13 9:11am
   
Solution for what? Return means it will return. If you want more than one value then don't return. What do you want?
Arbaz Ali 17-Jul-13 4:44am
   
i want to return more then 1 value
ZurdoDev 17-Jul-13 7:36am
   
Then concatenate the values together or return an array.
Arbaz Ali 17-Jul-13 8:41am
   
please give an example with code so i can easily understand i will be very thank full to u
ZurdoDev 17-Jul-13 8:45am
   
while (xreader.Red())
{
myvar += xreader[0].ToString() + "|";
}

return myvar;
Naz_Firdouse 16-Jul-13 9:16am
   
what is your exact requirement???
Please eloborate

1 solution

Use the following piece of code.

C#
List<string> lstIDs = new List<string>();
SqlDataReader xreader = xCmd.ExecuteReader();
while (xreader.Read())
{
 lstIDs.Add(xreader[0].ToString());
}
return lstIDs;
</string></string>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900