比较数据库中的值 [英] Compare values from database

查看:79
本文介绍了比较数据库中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用类似
的查询

select * from mew_file where process_id=6



我得到5行和5个列

现在我想用一个值lijr比较整个第三栏

if(reader["stage"]=100)
{
}


听到阶段是我的sql查询中的第三列,我该如何比较.

解决方案

在查询中使用WHEN-CASE,如果您有任何疑问,请不要

 ArrayList myarr =  ArrayList();
        for ( int  i =  0 ; i< ; ds.tables [ 0 ].rows.count; i ++)> 
       {

        myarr.Add(ds.Tables [ 0 ].Rows [i] [" ].ToString());

       }



现在,所有值都在"myarr"数组中.

然后,您可以为字符串分配要比较的内容.

之后,将该字符串与Array的每个元素进行比较.


使用数据集从数据库中获取数据,因为它的连接较少.
然后您可以通过这种方式进行比较:

数据集ds =  Dataset();
ds = // 获取数据到ds; 
 for ( int  i =  0 ; i< ; ds.tables [ 0 ].rows.count; >  {
  如果(Convert.ToInt32(ds.Tables [ 0 ].Rows [i] [ 2 ])==  100 )//  2是列的索引
   {
     // 您要在此处执行的代码; 
   }
  其他
   {
    // 其他条件
   }
} 



希望对您有所帮助.
如果有帮助,请不要忘记将其标记为答案. :)


i am using query like

select * from mew_file where process_id=6



I am getting 5 Rows with five cols

now i want to compare whole 3rd column with one valu lijr

if(reader["stage"]=100)
{
}


hear stage is the 3 rd column in my sql query I how can I compare.

解决方案

Use WHEN - CASE in query, if you have any doubt then don''t hesitate.


ArrayList myarr = new ArrayList();
       for(int i=0;i<ds.tables[0].rows.count;i++)>
       {

        myarr.Add(ds.Tables[0].Rows[i]["Third_ClumnName"].ToString());

       }



Now you have all values in "myarr" array.

Then, you can assign a string what you want to compare.

After that compare that string with each element of Array.


use dataset to fetch data from database, because it is connection less.
and then you can compare in this way :

Dataset ds=new Dataset();
ds= // get data into ds;
for ( int i=0; i<ds.tables[0].rows.count;>{
  if( Convert.ToInt32(ds.Tables[0].Rows[i][2])==100)  // 2 is index of column
   {
     // code here that u want to do;
   }
  else
   {
    // else condition
   }
}



Hope this will surely help you.
Don''t forget to mark as answer if it helps. :)


这篇关于比较数据库中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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