DataRow Array size

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
Is there any way of declaring an array of DataRow of variable size (or
dynamic array) in ADO.net as the fowwing syntax require the size of the array.

array<DataRow^>^ rows= gcnew array<DataRow^>(size);

I am searching my SQL Server2005 databases DataTable for a given column
value using DataTable::Select method and I don't know how many rows will it
return depending on the selection criteria.

Thanks for any help.

Manjree
 
DataTable is the standard object as collection for datarows.

Trying to set a DataTable in another array is a little bit impossible
because the DataRow needs is companion collection The DataColumns, which is
also part of the datatable.

Cor
 
Hello Manjree,
Thanks for Cor's help.

In general, DataTable is a collection for datarows.

For you case, have you tried the following line?
array<System::Data::DataRow^>^ rows=myTable->Select("...");

In my opinion, we need not to define the size for array. Table::Select
method will return the array for us.

Hope this helps.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Wen

I am still looking for the resolutio of my problem "How to store rows
returned by a selection criteria as the no. of rows returned are not fixed?"

I really appriciate your help.

Thanks.

Manjree
 
Manjree,

The rows are forever fixed even when they are in a collection, they belong
to a datatable.

See for that the property DataRow.Table

Cor
 
Hello Manjree,

Just as what Cor said, the Property Table->Rows->Count will return the
number of rows in current Table.
If rows retruned by Table::Select() method, Table->Select()->Length
proptery could tell us how many rows retruned by this selection criteria.

Try the following line:
array<System::Data::DataRow^>^ rows=gcnew
array<System::Data::DataRow^>(MyTable->Select("ID>100")->Length);
rows=MyTable->Select("ID>100");

Hope this helps. Please let me know if you have any more concern. It's my
pleasure to assist you. Have a great day.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Wen

I am trying the following code:

pSrchRows=gcnew array<DataRow^>((pSrchTable1->Select(L"pSrchColumn1= 'aaa'
"))->Length);

pSrchRows=(pSrchTable1->Select(L"pSrchColumn1 = 'aaa' "));

which is throwing System.Data.EvaluateException.
cannot find column [pSrchColumn1]

Though I've checked it is taking correct table (say Supplier) in pSrchTable1
and correct column (e.g. supplierID) in pSrchColumn1 and there is a record
with value supplierID = 'aaa' in the database.


Any help will be appriciated.

Thanks.
Manjree
 
Hello Manjree,

Try the following code line.
pSrchRows=gcnew array<DataRow^>((pSrchTable1->Select(L"supplierID = 'aaa'
"))->Length);

The column in the filter criteria should be the name of Column (supplierID)
rather than the name of object (pSrchColumn1).

http://msdn2.microsoft.com/en-us/library/det4aw50.aspx
[DataTable.Select Method (String)]

Hope this help. Please let me know if this works for you. I will follow up.
It's my pleasure to assist you.
Have a great day.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Wen

Thanks for the reply. It did work.

But the problem is that search can be on any column of any table selected
from comboBoxes in the GUI. So I set pSrchColumn1 to the selected column and
then use it.
Is there any other way round to resolve this problem?

Thanks.

Manjree
 
Hello Tomasz,
Thanks for your reply.

http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.columnname(V
S.80).aspx
[DataColumn.ColumnName Property]

DataColumn.columnName property returns the name of current DataColumn
object.

Please try the following method and let me know if this is what you need.
I'm glad to assist you.

pSrchRows=gcnew array<DataRow^>((pSrchTable1->Select( pSrchColumn1->
columnName + L" = 'aaa' ")->Length);

Hope this helps.
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Manjree,
Thanks for your reply.

I'm indeed sorry for the mistake of wrong name.
I replied Tomasz in the other post "Multiple INSERTs to Oracle in a single
command - how to?" in adonet newsgroup.
Sorry again for that.

But it is really great news that my method works for you.
Please feel free to let me know if you face any other issue next time. I'm
glad to assist you.

You are welcome, Manjree.:)

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top