如何搜索DataTable中的值
2024-07-21 02:22:33
供稿:网友
中国最大的web开发资源网站及技术社区,
gets a specified datarow.
overload list
gets the row specified by the primary key value.
[visual basic] overloads public function find(object) as datarow
[c#] public datarow find(object);
[c++] public: datarow* find(object*);
[jscript] public function find(object) : datarow;
gets the row containing the specified primary key values.
[visual basic] overloads public function find(object()) as datarow
[c#] public datarow find(object[]);
[c++] public: datarow* find(object*[]);
[jscript] public function find(object[]) : datarow;
example
[visual basic, c#] the following example uses the values of an array to find a specific row in a collection of datarow objects. the method presumes a datatable exists with three primary key columns. after creating an array of the values, the code uses the find method with the array to get the particular object desired.
[visual basic, c#] note this example shows how to use one of the overloaded versions of find. for other examples that might be available, see the individual overload topics.
[visual basic]
private sub findinmultipkey(byval mytable as datatable)
dim foundrow as datarow
' create an array for the key values to find.
dim findthesevals(2) as object
' set the values of the keys to find.
findthesevals(0) = "john"
findthesevals(1) = "smith"
findthesevals(2) = "5 main st."
foundrow = mytable.rows.find(findthesevals)
' display column 1 of the found row.
if not (foundrow is nothing) then
console.writeline(foundrow(1).tostring())
end if
end sub
[c#]
private void findinmultipkey(datatable mytable){
datarow foundrow;
// create an array for the key values to find.
object[]findthesevals = new object[3];
// set the values of the keys to find.
findthesevals[0] = "john";
findthesevals[1] = "smith";
findthesevals[2] = "5 main st.";
foundrow = mytable.rows.find(findthesevals);
// display column 1 of the found row.
if(foundrow != null)
console.writeline(foundrow[1]);
}
[c++, jscript] no example is available for c++ or jscript. to view a visual basic or c# example, click the language filter button in the upper-left corner of the page.