DatatableからSelectする処理のエラー

(++English Follows Japanese++)

□DatatableからSelectする処理のエラー

はじめまして。
win7で稼働している既存のRPAをwin10端末に対応させています。
下記のデバックがうまくいかず、お力添え頂けませんでしょうか。

<―――――――――――――――――――――
■周辺処理
・ExcelファイルAからデータを取得してデータテーブルに格納
取得したデータテーブルを変数に格納して整形 ←該当コード
変数データをExcelファイルBへ貼付け

■期待する処理
・データテーブル内の「項目名A」が空行のデータを削除した上で、変数に格納する

■該当コード
TMP_DataRow=DT_Item_Array(TMP_CountA).Select(“項目名A <> ‘’”)

■エラー内容
DataTable Select function cannot perform “<>” operation on System.Double and System.String

■試したデバック
-Select内を修正 →同様のエラー
Select(“項目名A <> “””)
Select(“項目名A<>‘’”)
Select(“項目名A<>’ '”)
Select(“項目名A ={0}”)
Select(“項目名A IS NULL”)
Select(“[項目名A] <> ‘’”) ←new(11/28)
Select(“[項目名A]<>‘’”) ←new(11/28)
-本処理をコメントアウト →次処理でエラー
※次の処理
TMP_DataRow.Count > 0
―――――――――――――――――――――――>
恐らく初歩的なテキスト挿入で躓いているのだと思いますが…。

RPA初心者の上こちらが初投稿のため内容に不備などございましたら恐れ入りますがご指摘頂けますと幸いです。
どうぞよろしくお願いいたします。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

□Error in processing to select from Datatable

Hello, nice to meet you.
Now I’m making compatible the RPA from win7 to win10.
Could you help me with the following debug?

<―――――――――――――――――――――――
■ Peripheral processing
・ Acquire data from Excel file A and store in data table
Store the acquired data table in a variable and format it. ← Corresponding code
Paste variable data to Excel file B

■ Expected processing
-Delete the data with blank “Item name A” in the data table and store it in the variable

■ The code
TMP_DataRow = DT_Item_Array (TMP_CountA) .Select (“Item name A <> ‘’”)

■Error details
DataTable Select function cannot perform “<>” operation on System.Double and System.String

■ Tried Debug
-Fixed in Select → Same error
Select (“Item name A <>” “”)
Select (“item name A <> ‘’”)
Select (“Item name A <> ‘’”)
Select (“Item name A = {0}”)
Select (“Item name A IS NULL”)
Select(“[Item name] <> ‘’”) ←new(11/28)
Select(“[Item name]<>‘’”) ←new(11/28)
-Comment out this process → Error in next process
(* Next processing: TMP_DataRow.Count> 0)
―――――――――――――――――――――――>
I think I got bogged at very basic grammer mistake…

I’m sorry but This is the first post for me at this forum and I’m new at RPA itself,
So I would be very appreciate if you could point out any deficiencies in this content.

Thank you.

Hi @sato_b

Try DT=DT.Select(“[A]<>‘’”).CopyToDatatable()

Thanks
Ashwin S

1 Like

!
Thank you for your quick reply!! I am going to execute it.

こんにちは

Seelctメソッドがうまくいかなければ、少々大袈裟ですが以下でも良いかも

TMP_DataRow=DT_Item_Array(TMP_CountA).AsEnumerable.Where(function(r) r("項目名A") IsNot Nothing andalso r("項目名A").ToString<>"")

いかがでしょうか?

1 Like

@AshwinS2 san
Thank you so much for your help.
I have tried;
TMP_DataRow = DT_Item_Array (TMP_CountA) .Select (“[ItemnameA]<>‘’”)
But the result is same error,

Cannnot perform ‘<>’ operation on System.Double and System.String

So, should I give up to copy&paste via “TMP_Data_Row”
and directly input the data from the DT to the new DT ?

@Yoichi さん
はじめまして、ご返信ありがとうございます!
またすごいコードを頂き大変ありがとうございます。
正直きちんと理解できては…ですが勉強いたします。

実はなるべく現状のxamlに大きな変更を加えたくなく…、、
でも構造としては AshwinS2さんにご教示頂いたものよりも現状に近いんですね…。。
できればTMP_DataRowは使いたいので、もう少しSelectで粘ってみて無理そうでしたら試させて頂きます。
重ね重ねありがとうございます。

こんにちは

ちなみにですが
TMP_DataRow はそのまま使えるようにしてますよ。
データテーブル中にヌル値があった時のことも想定して記述しているので少々長いですが...

追記:すみません最後に.toArrayが必要かもしれません

ご参考まで

1 Like

Hi @sato_b

Create a new Datatable as newDT=Dt.Select(“[ItemnameA]<>‘’”).CopyToDatatable()

It will work @sato_b
Thanks
Ashwin S

1 Like

@Yoichiさん
初めて通過しました!!本当にありがとうございます。
お察しの通り、ToArrayなしだとエラーでした。
試したのは下記です;

TMP_DataRow=DT_Item_Array(TMP_CountA).AsEnumerable.Where(function(r) r(“項目名A”) IsNot Nothing andalso r(“項目名A”).ToString<>“”).ToArray

が、こちらループ処理なのですが(後出しですみません、上に記載します)、
2回目の処理でエラーが出てしまいました…。;

Column ‘項目名A’ does not belong to table.

調べますが、別投稿でご質問差し上げるかもしれません。
とりいそぎ。

2 Likes

@AshwinS2 san
Thank you again for your help, and sorry for Japanese.

Actually, I would like to use “TMP_DataRow” if it is possible,
because use it next process (Very sorry for late information).

So I’m trying the code which @Yoichi san gave me;

TMP_DataRow=DT_Item_Array(TMP_CountA).AsEnumerable.Where(function® r(“項目名A”) IsNot Nothing andalso r(“項目名A”).ToString<>“”). ToArray

But there is error

Column ‘項目名A’ does not belong to table.

So I’m trying to debug this error now.

But if I can’t solve this problem, I will try to create new Datatable without “TMP_DataRow”.

Thank you so much again for your support.

@Yoichi さん

こちらの修正ですが、

if文
DT_Item_Array(TMP_CountA).Columns.Contains("項目名A")


TMP_DataRow=DT_Item_Array(TMP_CountA).AsEnumerable.Where(function® r(“項目名A”) IsNot Nothing andalso r(“項目名A”).ToString<>""). ToArray

の前に追加し、前後の処理をくくったところ、うまく流れました。
大変ありがとうございました。

まだ後続処理で不安なところがあるため再度修正を加えるかもしれませんが、
とりいそぎお礼まで…

2 Likes

背景を十分に理解できていなかったら申し訳ないのですが、"Filter Data Table"アクティビティでは動作しませんでしょうか……?

1 Like

こんにちは

当方の理解ですが、

背景的には

win7で稼働している既存のRPAをwin10端末に対応させています。

ので

実はなるべく現状のxamlに大きな変更を加えたくなく…、、

との意向があり
DataRow配列であるTMP_DataRowに結果を入れてあげたいというのがニーズかと思います。

もう少し全体に手を入れても良いならFilter Data Tableアクティビティも選択肢になりうると思います。

2 Likes

@cheez_RPA さん
ご返信ありがとうございます。
@Yoichiさんのご返信にある通り、TMP_DataRow を後の処理で使いたかったのと、
なるべく部分的な改修で済ませたかったため、上記のコードを採用させて頂きました。

Datatableからの抽出にはFilter Data Tableアクティビティが一般的なんですね…ご教示ありがとうございます。
(参考:https://www.cresco.co.jp/blog/entry/6236/)
今後自力で作成する際には活用させて頂きます。

@Yoichiさん
後続処理が無事通過しましたため、上記の
TMP_DataRow=DT_Item_Array(TMP_CountA).AsEnumerable.Where(function® r(“項目名A”) IsNot Nothing andalso r(“項目名A”).ToString<>""). ToArray
にて改修いたしました。

以下蛇足になりますが…
・AsEnumerable メソッドはLINQの一部なのですね。
恥ずかしながらLINQを知らず勉強になりました。
・Select文を懲りずにその後何度か試しましたがうまくいかず、
Datatable→selectができない原因を調べましたが、それらしいものは見つからず…
判明したらまたこちらに投稿いたします。

大変ありがとうございました。

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.