简体   繁体   English

如何通过for循环从DataTable中检索n个行

[英]How to retrieve n number of rows from DataTable through for loop

Hi i am facing problem while i am trying to retrieve the data from the database which encrypted, during sending data into database. 嗨,我在将数据发送到数据库期间尝试从加密的数据库中检索数据时遇到问题。

Now i want decrypted the data during retrieving time and view it in Data grid-view control. 现在,我想在检索期间解密数据,并在“数据网格视图”控件中查看它。 I have decrpyt function as well which is like decrypted(string Decrypting);. 我也有decrpyt函数,就像decrypted(string Decrypting);。 But the issue is i am not able to implement the Loop and implement the decrypted function so that i can get actual data into data Grid-View control. 但是问题是我无法实现Loop并无法实现解密功能,因此我无法将实际数据放入数据Grid-View控件中。 Please help me that will be appreciated. 请帮助我,将不胜感激。

  public void SelectData() {   try    {  DataTable dt = new SQLTool().ExecuteOutput("Select * from CustomerTable where Date  between '" + TextBox1.Text.Trim() + "' and '" + TextBox2.Text.Trim() + "'");       

        gvCustomerDetails.DataSource = dt;           

    }
    catch (Exception)
    {

    }

    //Button2.Enabled = true;
    //Button1.Enabled = false;


}

在将dt作为数据源分配给数据网格之前,可以解密dt中的数据并进行更新。

You need to loop through every record and place at the smae spot 您需要遍历每条记录并将其放置在smae位置

Just Try Adding 只需尝试添加

for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
    dt.Rows[i][j] = decrypted(dt.Rows[i][j].ToString());
}
}

Try this 尝试这个

for (int i = 0; i < dt.Rows.Count; i++)
{
   for (int j = 0; j < dt.Columns.Count; j++)
   {
       dt.Rows[i]["column_name"] = YourDecriptionFunction(dt.Rows[i]["column_name"].ToString());
   }
}

Try something like this: 尝试这样的事情:

dt.Rows.AsEnumerable().ForEach(x => dt.Columns.ToList().ForEach(y => dt.Rows[x][y] = decryptedFunction(dt.Rows[x][y].ToString())))

**Is untested, but it's suppose to go through every row and columns decrypting and storing in the same row, column **未经测试,但假设对每一行和每一列进行解密并存储在同一行,同一列中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM