Formatting CSV file

saidev

Active member
Joined
Dec 22, 2005
Messages
27
Programming Experience
1-3
Hi Guys,

I am retrieving the data from AD and sending it to th CSV file. but the data is not coming in Column1,column2 and Column3. Can you guys help me with formatting. PLease see my code below.

Try

dirEntry = New System.DirectoryServices.DirectoryEntry("LDAP://Servername/DC=ffe,DC=fcted,DC=com")

dirSearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)


Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter("\c:Users.csv")


For Each sResultSet As SearchResult In dirSearcher.FindAll
objStreamWriter.Write(GetProperty(sResultSet, "employeenumber"))
objStreamWriter.Write(GetProperty(sResultSet, "mail"))
objStreamWriter.WriteLine(GetProperty(sResultSet, "samaccountname"))

Next
objStreamWriter.Close()
Catch ex As Exception
End Try


When i export the data to Excel the 3 fields i am retrieving are merged. Can you guys help me on how to get the data into excel with individual columns? Appreciate your help. Please see below(currently it is exporting like below)

41693Kei.Wetzle@sports.netKWetzle
 
What does CSV stand for? It's Comma-Separated Values. Where are you separating your values with commas?

This is new to me, never done that. Can you pls help me on how to do this? so that when i export to the csv file i will get that data in 3 separate columns? Thanks for your help.
 
So, what does the file look like and what is it supposed to look like? What's the difference?

currently the file looks like this.

41693Kei.Wetzle@sports.netKWetzle

it suppose to look like 41693,kei.Wetzle@sports.net,KWetzle

when i export to csv each field has to be in separate column or with comma. so that i can export the data to sql table. Thanks
 
I'm not sure that you're really putting a lot of thought into this. Obviously the difference between this:
41693Kei.Wetzle@sports.netKWetzle
and this:
41693,kei.Wetzle@sports.net,KWetzle
is that the first one does not contain commas while the second one does. Everything in the file is there because you wrote it and the commas are missing so obviously you didn't write the commas. You don't need any programming experience to work out what to do from there.
 
I'm not sure that you're really putting a lot of thought into this. Obviously the difference between this:and this:is that the first one does not contain commas while the second one does. Everything in the file is there because you wrote it and the commas are missing so obviously you didn't write the commas. You don't need any programming experience to work out what to do from there.

Hi, Is it possible to dump this data into sql table instead of CSV File? if possible can you help me with VB.Net code on how to dump this data to sql table? Thanks for your help.
 
Hi, Is it possible to dump this data into sql table instead of CSV File? if possible can you help me with VB.Net code on how to dump this data to sql table? Thanks for your help.

Populate a DataTable and use a data adapter to save all the data to the database in one batch. You can find an example of that, as well as various other common ADO.NET tasks, here:

Retrieving and Saving Data in Databases
 
Back
Top