Foreach循环从数据表中获取所有行值 [英] Foreach loop to get all rows value from datatable

查看:682
本文介绍了Foreach循环从数据表中获取所有行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示每个循环的所有行数据请给我一些想法

如果可以使用if块中的每一个

How to show all rows data with for each loop please give me some idea
how can use for each in if block

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 "";
       }





我尝试过:



尝试使用jqury webmethods显示所有行数据



What I have tried:

Try to show all rows data with jqury webmethods

推荐答案

hi实际上,如果您真的使用Datatable意味着您可以使用Ajax或Json使用这个你可以很容易地得到所有的行值并显示到数据表...



然后,

访问此链接你会得到你的答案:



如何将所有DataTable行检索到C#中的List? |丰富的代码 [ ^ ]
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[^]


这篇关于Foreach循环从数据表中获取所有行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆