how do you get data from csv to windows form

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Hi to all.
I am new to Visualbasic.net and windowz programming in general so I hope
someone can help.
I am trying to get info from a csv (Excell) file into a windows form.
For instance I want to get the totals of one "column" and put it into a
textbox on a form when I press a button. I did not think it would be
difficult to do , but I cant seem to get it right.
I have managed to get a datagrid working , using the oledbDataAdapter
,oledbconnection and Dataset stuff on the form with a MSAccess .mdb
file(More by luck than anything else) , but this is not really what I want.

Has anyone got a simple approch that accesses a csv file on say c:\data
\mycsvfile.csv and puts the total of the first column in a textbox
on a form , when I press a button. If I can get that working , I' may be
able to go from there.
I'm sure some query like: (Select count(*) from myfile.csv where column =
"something " ) , will be needed , but as I said I'm new to this stuff and I
may be barking up the wrong tree altogether.
Thanks
Rob
 
Rob said:
I am trying to get info from a csv (Excell) file into a windows form.
For instance I want to get the totals of one "column" and put it into a
textbox on a form when I press a button. I did not think it would be
difficult to do , but I cant seem to get it right.
I have managed to get a datagrid working , using the oledbDataAdapter
,oledbconnection and Dataset stuff on the form with a MSAccess .mdb
file(More by luck than anything else) , but this is not really what I
want.

<URL:http://www.connectionstrings.com/>
-> "Text"
 
Thanks for the help guys , but I am still struggeling here. As I said
I'm new to this and I don't really have the background knowledge
needed.
I am trying to put a total for instance into a textbox. this is my
code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim file As String = "Test.csv"
Dim path As String = "C:\"

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & _ path & ";Extended
Properties=""Text;HDR=no;FMT=Delimited\"""

Dim conn As New OleDbConnection(ConStr)
Dim qwerty As New OleDb.OleDbCommand("Select count(*) from
test.csv " & file,conn)
TextBox1.Text = qwerty.ExecuteScalar '******BOMBS out
here****

End Sub


Formatting is not great here.
It seems to get as far as running the actual query then crashes. I can
get code like this to work on an .mdb file , but that has collumns
that are named etc. This csv file has nothing like that.If you open
the csv file in Excel the column's are "named" A to P , like a normal
spreadsheet.
I get a feeling my query may be badly structured , although I have
tried
lots of variations with the same result.
I have Microsoft ADO,net step by step , but nowhere does it mention
CSV files.

Any help appreciated
Cheers
Rob
 
Me again guys.
Got the problem sorted. I forgot to open the "@##$%%^" connection.
Starting to get some results now.
Cheers
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top