473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

load .csv data to a datagrid

Hi this is the code i have written.
my csv file looks lke this
Column1,Column2,Column3
1,1,1
43,43,4
132,234,243
54,53,46

but still i get only
null null null
null null null
null null null
in my datagrid - what should i do.

Dim cn As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")
Dim da As New OleDbDataAdapter

Dim ds As New DataSet
Dim cd As New OleDbCommand("SELECT * FROM C:\Test1.csv", cn)
cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
DataGrid1.DataSource = ds.Tables(0)
cn.Close()

Mar 13 '06 #1
2 4733

"with a question" <Pr***********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi this is the code i have written.
my csv file looks lke this
Column1,Column2,Column3
1,1,1
43,43,4
132,234,243
54,53,46

but still i get only
null null null
null null null
null null null
in my datagrid - what should i do.

Dim cn As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")
Dim da As New OleDbDataAdapter

Dim ds As New DataSet
Dim cd As New OleDbCommand("SELECT * FROM C:\Test1.csv", cn)
cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
DataGrid1.DataSource = ds.Tables(0)
cn.Close()


I would change two things:
where you have HDR=No, I would change it to : Yes ( you have column names in
your data you are showing here)
Second change:
Datagrid1.DataSource = ds.Tables(0)
to:
Datagrid1.Datasource = ds.Tables(0).DefaultView

That should get you going.
james
Mar 13 '06 #2
God I love newsgroups. I've spent 10+ hours searching for how to do just
this. Then I remember newsgroups and bingo - I'm in.

Thanks guys.

(Been a while since I picked up VB and now it's VB.net and I'm just flailing
madly through).
"james" <jj***************@earthlink.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

"with a question" <Pr***********@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi this is the code i have written.
my csv file looks lke this
Column1,Column2,Column3
1,1,1
43,43,4
132,234,243
54,53,46

but still i get only
null null null
null null null
null null null
in my datagrid - what should i do.

Dim cn As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")
Dim da As New OleDbDataAdapter

Dim ds As New DataSet
Dim cd As New OleDbCommand("SELECT * FROM C:\Test1.csv", cn)
cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
DataGrid1.DataSource = ds.Tables(0)
cn.Close()


I would change two things:
where you have HDR=No, I would change it to : Yes ( you have column names
in your data you are showing here)
Second change:
Datagrid1.DataSource = ds.Tables(0)
to:
Datagrid1.Datasource = ds.Tables(0).DefaultView

That should get you going.
james

Mar 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
by: duncan | last post by:
Hi I an a mebie to XML / vb.net and I am struggling. I am developing a web base applcation using XML to link to its database so. Here is the XML I want to load into to a datagrid. The...
1
by: Soul | last post by:
Hi, I have a DataGrid which works. But if I load a new table to the DataGrid, it will still show those old data I load earlier. private void loadTableA() { if ( openFileDialog.ShowDialog()...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
1
by: Biva | last post by:
Hello, I have a drop down list control in a datagrid. I can't seem to populate the control. Here is what my code looks like: <EditItemTemplate> <asp:DropDownList ID= "ddlUser5" DataSource =...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
1
by: DotNetJunkies User | last post by:
Hi, I was wondering if it is possible to load datagrid into datalist programatically using ITemplate interface with the following structure and place intp placeholder control. PlaceHolder -...
15
by: H00ner | last post by:
Hello All Hope you can help Been pulling my hair out about a popup problem in ASP.NET. One of the forms i wrote requires the user to select a product from a list in a popup web form. the...
2
by: Jeff_Mac | last post by:
Hi there. I'm a bit of a newbie, and I would appreciate any help that anyone can give me on an error I'm getting with Crystal Reports. Every time I attempt to view a report using the Crystal...
3
by: Ky | last post by:
Can i user dataset partially load the data to datagrid depends on the scoll bar moving? seems like power builder have this function of the data browser/windwows (i forgot), but it can partially...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.