我如何在数据行上使用foreach [英] how do i use foreach on datarow

查看:269
本文介绍了我如何在数据行上使用foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定数据表中的输入值是否等于1.我已经使用datarow select方法返回满足特定ID的数据表中的所有行,现在我想遍历这些返回的行以查找输入值和数据表中的内容之间是否存在匹配项.我似乎找不到合适的方法来做到这一点.任何帮助深表感谢.我的代码如下:

I want to find out if an input value is equal to one in the datatable. I have used the datarow select method to return all rows in the datatable meeting a certain ID, now i want to loop through these returned rows to find if there is a match between the input value and whats in the datatable. I cant seem to find the proper way to do this. Any help is much appreciated. my code is below:

DataRow[] foundrows = cvmanagerDataSet1.Tables["role"].Select("dept_id = '"+id+"'");
                    foreach(DataRow dr in foundrows)
                         {
                          //  role = foundrows[0].ItemArray[2].ToString();
                            MessageBox.Show(dr["role"]);
                            if (role1.Text == role)
                            {
                                MessageBox.Show("The role '" + role1.Text + "' already exists for this department", "Duplicate role names", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                                //break;
                            }
                            else
                            {
                                addedroles.Items.Add(role1.Text);
                                role1.Text = "";
                                bttnremove.Enabled = true;
                                bttnreset.Enabled = true;
                                bttndone.Enabled = true;
                                break;
                            }
                          }

推荐答案

您的意思是如何从DataRow中获取数据吗?

Do you mean how to get data out of the DataRow?

foreach (DataRow DR in MyRows)
{
    String Data = DR["Name"] as String;
}


这篇关于我如何在数据行上使用foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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