如何只检索1列 [英] How to retrieve only 1 column

查看:89
本文介绍了如何只检索1列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码,我想要检索唯一的一列。并且每个值都与活动或活跃的唯一值进行比较



我尝试过:



i有一个使用datagridview的贷款扣除表格,制作一个代码,其算法是



i am using this code, i want to retrieve the only one column. and each value compare with unique value active or in active

What I have tried:

i have a loan deduction form using datagridview, make a code its algorithm is that

DataTable dt = new DataTable();
OleDbDataAdapter dad = new OleDbDataAdapter(query1, conn);
dad.Fill(dt);
EmpsID.Text = dt.Rows[0][0].ToString();
if (EmpsID.Text != textBoxEmpsID.Text)
{
    dataGridView1.CurrentRow.Cells[5].Value = "0";
}
else
{
    Instalment_Amount.Text = dt.Rows[0][3].ToString();
    Status.Text = dt.Rows[0][5].ToString();
    conn.Close();
}
if (Status.Text == "Active")
{
    dataGridView1.CurrentRow.Cells[5].Value = Instalment_Amount.Text;
}
else
{
    dataGridView1.CurrentRow.Cells[5].Value = "0";
}



工作但只从状态列中检索第一个值。但是如果任何人有一个以上的贷款并且其状态是活跃的,在这种情况下这个代码正在运行。但如果它的第一个状态是非活动状态,那么它不会从贷款表中检索数据。

i想要设置如果状态列的第一个值处于非活动状态,那么代码将检查状态列的下一个值,如果下一个值也处于非活动状态,那么它将检查下一个值,直到状态为活动状态

请告诉我解决方案.....


its working but only first value retrieve from status column. But if any person have more then one loan and its status is active in this case this code is working.but if its first status is inactive then its not retrieve the data from loan table.
i want to set it if first value of the status column is inactive then the code will check the next value of the status column if next value is also inactive then it will check the next value this continue till the status found active
please tell me the solution.....

推荐答案

使用循环...



认真地,使用循环(for或foreach)循环遍历DataTable的行 - 此时您只检查一行,因此您只得到一个结果。
Use a loop...

Seriously, use a loop (for or foreach) to loop though the rows of the DataTable - at the moment you only examone a single row and so you only get a single result.


这篇关于如何只检索1列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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