SQL Table to csv with delimiters

Hi,

I have read data from SQL Table and stored in a data table.

Read the data table as input and used write range to write to csv file…

I want to use two delimiters (double quotes and comma). I am able to achieve only comma at the moment.

Please guide me in achieving this. Attached expected csv output format.

1 Like

Hey @aishwarya1

Could you please try with Output Data Table activity ?

Thanks
#nK

Hi,

I tried, only comma between values are coming.

I want double quotes too like the image attached above.

1 Like

Oh okay for all the values you need to enclose it within double quotes right ?

Thanks
#nK

Yes, exactly.

1 Like

Hey @aishwarya1

Please try this,

String.Join(Environment.NewLine, dt_DbData.AsEnumerable.Select(Function(row) String.Join(",",row.ItemArray.Select(Function(columnVal) """"+columnVal.ToString+""""))))

Hope this helps

Thanks
#nK

1 Like

Thanks a lot, it worked but the column headers are not coming.

Can you help me do the same for the headers as well ?

1 Like

Hey @aishwarya1

Sorry for missing it,

Here you go,

String.Join(",",dt_DbData.Columns.Select(Function(col) """"+col.ColumnName+""""))

Now concat both query results

Header query + Environment.Newline + Above Query For Values 

Thanks
#nK

I am getting the below error for Header query

Validation Error Compiler error(s) encountered processing expression “String.Join(”,",output_dt.Columns.Select(Function(col) “”""+col.ColumnName+""""))".
‘Select’ is not a member of ‘System.Data.DataColumnCollection’. Main.xaml

1 Like

Hey @aishwarya1

Ok I guess it’s due to collection - so now it’s just converted to iEnumerable of column,

String.Join(",",dt_DbData.Columns.Cast(Of DataColumn).Select(Function(col) """"+col.ColumnName+""""))

Thanks
#nK

1 Like

Thank you so much. It worked :slight_smile:

1 Like

Cool @aishwarya1 :slight_smile: :+1:

1 Like

Could you please help me with another issue if possible?

I want to insert a Datatable to a SQL Table. I am not sure how to do it.

Should I create a table first and then insert ? How will the columns be mapped between datatable and SQL Table?

1 Like

Hey @aishwarya1

Yes you are right !

Thanks
#nK

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