Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to show all rows data with for each loop please give me some idea
how can use for each in if block
C#
public static string Getdata(string Id)
       {
           string SQL = "select * from testtable where UserId='"+Id+"'";
           DataTable DATA = new DataTable();
           SqlDataAdapter DTA = new SqlDataAdapter(SQL,cnnx);
           DTA.Fill(DATA);
           if (DATA.Rows.Count > 0)
           {
               return DATA.Rows[0].ItemArray[0].ToString();
           }
           return "";
       }


What I have tried:

Try to show all rows data with jqury webmethods
Posted
Updated 12-Apr-16 0:43am
v2
Comments
deepankarbhatnagar 12-Apr-16 6:33am    
Please show your code what you have done
Arslan saif 12-Apr-16 6:41am    
public static string Getdata(string Id)
{
string SQL = "select * from testtable where UserId='"+Id+"'";
DataTable DATA = new DataTable();
SqlDataAdapter DTA = new SqlDataAdapter(SQL,cnnx);
DTA.Fill(DATA);
if (DATA.Rows.Count > 0)
{
return DATA.Rows[0].ItemArray[0].ToString();
}
return "";
}
for each loop in if block how can i do this
Karthik_Mahalingam 12-Apr-16 7:36am    
what do u want to do exactly?
Arslan saif 12-Apr-16 7:38am    
apply for each loop in if block

1 solution

hi Actually if You are Really Using Datatable means you can use Ajax or Json by using this you can easily to get all the rows value and display through to datatable...

Then,
visit this Link You will get your answer:

How to retrieve all Rows of the DataTable to a List in C#? | Abundant Code[^]
 
Share this answer
 

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