Data Binding with CSV Files

B

bbepristis

Hey all I maybe way off base here but I am trying to do a select * from
'csv file' then take the return data and insert it into textboxes for
example column company into companytxt.text ext... here is the code i
have so far but how do I bind this together? I am fairly new to vb.net
so please be understanding... here is my code:

Dim conStr As String =
"PageTimeout=5;Extensions={txt,csv,tab,asc};MaxScanRows=25;DefaultDir=C:\Documents"
& _
" and Settings\Brian\My Documents\Visual Studio
Projects;FILEDSN=C:\Program Files" & _
"\Common Files\ODBC\Data
Sources\multicam.dsn;DriverId=27;UserCommitSync=Yes;FIL=" & _
"text;UID=admin;Driver={Driver da Microsoft para
arquivos texto (*.txt; *.csv)};M" & _
"axBufferSize=2048;Threads=3;SafeTransactions=0"
Dim sqlStr As String = "SELECT * FROM 'multicam.csv'"
Dim conn As Odbc.OdbcConnection = New
Odbc.OdbcConnection(conStr)
conn.Open()
Dim da As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter(sqlStr, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Multicam")
DataGrid1.DataSource = ds.DefaultViewManager
conn.Close()

Thankx
 
P

Pete

bbepristis said:
Hey all I maybe way off base here but I am trying to do a select * from
'csv file' then take the return data and insert it into textboxes for
example column company into companytxt.text ext... here is the code i
have so far but how do I bind this together? I am fairly new to vb.net
so please be understanding... here is my code:

Dim conStr As String =
"PageTimeout=5;Extensions={txt,csv,tab,asc};MaxScanRows=25;DefaultDir=C:\Documents"
& _
" and Settings\Brian\My Documents\Visual Studio
Projects;FILEDSN=C:\Program Files" & _
"\Common Files\ODBC\Data
Sources\multicam.dsn;DriverId=27;UserCommitSync=Yes;FIL=" & _
"text;UID=admin;Driver={Driver da Microsoft para
arquivos texto (*.txt; *.csv)};M" & _
"axBufferSize=2048;Threads=3;SafeTransactions=0"
Dim sqlStr As String = "SELECT * FROM 'multicam.csv'"
Dim conn As Odbc.OdbcConnection = New
Odbc.OdbcConnection(conStr)
conn.Open()
Dim da As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter(sqlStr, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Multicam")
DataGrid1.DataSource = ds.DefaultViewManager
conn.Close()

Thankx

Hi,

You can use the Databinding property on your textbox after you have
filled your dataset i.e.

Dim conStr As String =

"PageTimeout=5;Extensions={txt,csv,tab,asc};MaxScanRows=25;DefaultDir=C:\Documents"
& _
" and Settings\Brian\My Documents\Visual Studio
Projects;FILEDSN=C:\Program Files" & _
"\Common Files\ODBC\Data
Sources\multicam.dsn;DriverId=27;UserCommitSync=Yes;FIL=" & _
"text;UID=admin;Driver={Driver da Microsoft para
arquivos texto (*.txt; *.csv)};M" & _
"axBufferSize=2048;Threads=3;SafeTransactions=0"
Dim sqlStr As String = "SELECT * FROM 'multicam.csv'"
Dim conn As Odbc.OdbcConnection = New
Odbc.OdbcConnection(conStr)
conn.Open()
Dim da As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter(sqlStr, conn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Multicam")

companytxt.DataBindings.Add("Text",ds, "Company")

OR

If you want to a list of company names from the CSV file, you can use a
listbox with DataTable and DataRow . Which would go something like
this:

Dim ds As DataSet = New DataSet
da.Fill(ds, "Multicam")

Dim myTable as Datatable
Dim myRow as Datarow
mytable = ds.tables("Multicam")

for each myRow in myTable.Rows
listbox1.Items.Add(myRow.item("company").tostring)
Next myRow

You can also use listview, if you want the code for that let me know.

Be warned I used these methods in one of my first programs and had to
rewrite it all into classes as I expanded the program. If this program
is just a sample or a one off then the above methods should be OK.

Thanks,

Pete.
 
B

bbepristis

Hey pete I tried this and now when I debug for some reason it takes
forever never loads the window I have to kill it. so I commented out
the line you gave and it still dosent work do you see anything else
below that could cause this?
 

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

Top