Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
First of all I am a total noob at programming, but I have a .csv file and I want to make it into a datatable in visual studio. From there I think I can figure out how to take the values from the data table and format them into a properly formatted text file.

(the end goal is to take a .csv format from a flashcard program called mentalcase and convert it to anki importable files)

I found this on this site: CSV Reader

but I have no idea idea how to open it or use it. all i need to know is where to put a file location and what my output data table will be called...

please help! I'm a struggling med student and I need to use flashcards made for proprietary mac software

Thank you!!
Posted

1 solution

Public Function GetCsvData(ByVal strFolderPath As String, ByVal strFileName As String) As DataTable

Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFolderPath & ";Extended Properties=Text;"
Dim conn As New OleDbConnection(strConnString)

Try
conn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM [" & strFileName & "]", conn)
Dim da As New OleDbDataAdapter()

da.SelectCommand = cmd

Dim ds As New DataSet()

da.Fill(ds)
da.Dispose()

Return ds.Tables(0)
Catch
Return Nothing
Finally
conn.Close()
End Try

End Function



Second Solution:Convert CSV File to data table[^]



Third Solution:
]]>


Sub Page_Load (Sender As Object, E As EventArgs)
If Not IsPostBack Then
Dim MyFileName as String
Dim ObjectStreamReader as System.IO.StreamReader
Dim ColorTable As New System.Data.DataTable("Colors")
Dim fileRow() As String
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow

dc = new System.Data.DataColumn("Hex",GetType(String))
ColorTable.Columns.Add(dc)
dc = new System.Data.DataColumn("String",GetType(String))
ColorTable.Columns.Add(dc)

MyFileName = Page.MapPath("Data.csv")

Try
ObjectStreamReader = new System.IO.StreamReader (MyFileName)
While ObjectStreamReader.Peek() > -1
dr = ColorTable.NewRow()
fileRow = ObjectStreamReader.ReadLine().Split(",")
dr(0) = fileRow(0)
dr(1) = fileRow(1)
ColorTable.Rows.Add(dr)
End While
Label1.Text = "Select a color:"
DropDownList1.DataSource = ColorTable
DropDownList1.DataTextField = "String"
DropDownList1.DataValueField = "Hex"
DropDownList1.DataBind()

Catch ObjectError as Exception
Label1.Text = ObjectError.Message
DropDownList1.Visible = False
Finally
If Not ObjectStreamReader Is nothing Then
ObjectStreamReader.Close()
End If
End Try
End If
End Sub










 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900