Saving specific datatable rows to excel sheet

datatable
excel
variable

#1

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!


#2

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


#3

@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


#4

@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.


#5


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"


#6

@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


#7

currently 4 for practice
Capture4


#8

@zahin did you tried above method.


#9

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


#10

@zahin method name is ImportRow


#11

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