Saving specific datatable rows to excel sheet

I am automating a data entry process(user creation) where I am working with multiple rows with multiple columns holding values(may contain blank or null). So, I want my program to read rows one by one and create users while saving rows with missing values in a excel sheet(without creating a user). I have used a “IF” condition that only creates user that does not have any missing values. I am also facing problem using multiple conditions in a “IF” statement!
Capture2

@zahin use row(“rowname”).toString<>“”

@Manjuts90 thank you for replying. I have used row(“rowname”).toString<> for writing data in specified text boxes(while creating username by filling online form)! my question is how can i save a specific row from my “ELSE” part of the code in a excel sheet

@zahin create dataTable with columns as many as in excel use datarow activity in else part. After loop completion u write that datatable to new excel for ur reference.

1 Like


row is used in for each loop and dtout is newly created datatable.
i have used a write range with dtout at the end of the for each loop. but its giving an error saying -
"Main(Autosaved) has thrown an exception

Source: Add data row

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException"

@zahin i am not sure about ur error try below method instead of add data row in else part. In place of “dt1” give ur target datatable name

Capture

currently 4 for practice
Capture4

@zahin did you tried above method.

i am not familiar with invoke method. what will be the whole process?

@zahin method name is ImportRow

Hi Zahin,

This error occurs when the Datarow (here its row variable) is empty/blank (all columns).
Probably you need to add one more condition using IF

 String.IsNullOrEMpty(String.Join("",row.ItemArray()))

If its true, then you can add a new row in the dtOut using Add Data Row with the following specified properties,

DataRow - dtOut.NewRow
Datatable - dtOut

If its false, add data row wont work [Error : The datarow already belongs to the other table]
In such case use ImportRow as mentioned by Manju, with following properties,

 TargetObject - dtOut
 MethodName - ImportRow
 Parameters ->
 IN - System.Data.DataRow - row

leave the rest of the properties as empty

1 Like