如何使用列值将Row添加到datatable中并将该行存储到数组或数据表中; [英] How to find a Row into datatable using column value and store that row into array or datatable ;
本文介绍了如何使用列值将Row添加到datatable中并将该行存储到数组或数据表中;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DataTable CheckRecord = new DataTable();
try
{
DataRow[] arr = SoftwareRequiremetGV_Table.Select("Software='" + Drpdwn_Software.SelectedItem.Value.ToString() + "'");
CheckRecord = arr.CopyToDataTable();
if (CheckRecord.Rows.Count > 0)
{
ShowMessage("Record Already Inserted,Duplicate Record Not Allowed !");
}
}
但是如果没有与Dropdown选择值匹配的行,那么它会创建一个错误意味着如果没有找到行然后生成错误。
此代码点 - -
but if not row matched with Dropdown selected value then it create an error means if no row found then error is generated .
at this point of code ---
CheckRecord = arr.CopyToDataTable();
错误是 - 源不包含DataRows。< br $> b $ b
请帮我解决这个问题...
Error is -The source contains no DataRows.
Kindly help me to resolve this issue...
推荐答案
检查从中返回的数组的长度选择
方法:
Check the length of the array returned from theSelect
method:
DataRow[] arr = SoftwareRequiremetGV_Table.Select("Software='" + Drpdwn_Software.SelectedItem.Value + "'");
if (arr.Length > 0)
{
ShowMessage("Record Already Inserted,Duplicate Record Not Allowed !");
}
从代码示例中不清楚是否需要调用 CopyToDataTable
方法。如果这样做,只有在数组不为空时才调用它:
It's not clear from your code sample whether you need to call the CopyToDataTable
method at all. If you do, only call it if the array is not empty:
DataRow[] arr = SoftwareRequiremetGV_Table.Select("Software='" + Drpdwn_Software.SelectedItem.Value + "'");
if (arr.Length > 0)
{
ShowMessage("Record Already Inserted,Duplicate Record Not Allowed !");
DataTable CheckRecord = arr.CopyToDataTable();
...
}
这篇关于如何使用列值将Row添加到datatable中并将该行存储到数组或数据表中;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文