Professional Documents
Culture Documents
Import CSV File Into Datagrid - Xtreme Visual Basic Talk
Import CSV File Into Datagrid - Xtreme Visual Basic Talk
t=251869
Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > import csv file into datagrid
Advertisement:
01-25-2006, 09:18 PM #1
Can i import csv file into datagrid? Please advice on the following
code?
Code:
For i = n - 1 To 0 Step -1
desc &= filename.Trim.Substring(i, 1)
Next
DS = New DataSet
DS.Clear()
myAdp.Fill(DS)
Last edited by wayneph; 01-26-2006 at 12:20 PM. Reason: please use [vb] tags for posting code
01-26-2006, 12:23 PM #2
Retired Moderator
* Expert *
(The first thing I notice is your Connection String Is pointed to Excel, not Jet...)
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
02-08-2006, 02:45 AM #3
1 of 4 26/01/2013 13:04
import csv file into datagrid - Xtreme Visual Basic Talk http://www.xtremevbtalk.com/showthread.php?t=251869
Thanks for your reply, i had change my coding that can accept csv file format, as below
____col1 col2
row1 1 K456K021-02-1
row2 2 846548621
so as usual, i try to display the data into datagrid but the (row1,col2) data display as null.... do you know how to
solve this problem
please advice.... your comment is very valuable to me
thanks
02-08-2006, 08:53 AM #4
Retired Moderator
* Expert *
it looks like it's "assuming" that column two is an integer. since it contains letters it is failing. Try declaring your
table first with the second column declared as a string. see if that helps.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
02-08-2006, 10:25 AM #5
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
02-08-2006, 09:52 PM #6
wayneph,
how do i declare the column two as string using VB .Net? but i had try to do it in excel by changing the format
cell into Text/General... but i still read it as null
silenuz,
thanks for you code, but i think your code capable under VB but not in VB .Net
02-09-2006, 08:48 AM #7
2 of 4 26/01/2013 13:04
import csv file into datagrid - Xtreme Visual Basic Talk http://www.xtremevbtalk.com/showthread.php?t=251869
MyReader.TextFieldType = FileIO.FieldType.Delimited
Dim i As Integer = 0
currentRow = MyReader.ReadFields()
'here you'd probably want to create actual column names for instead
'of just fieldi
For Each currentField In currentRow
i += 1
'the first "Field" & i.tostring sets column name, the second
'the column header
DataGridView1.Columns.Add("Field" & i.tostring, "Field" & i.tostring)
Next
02-09-2006, 09:27 AM #8
Retired Moderator
* Expert *
For mine, you need to create the DataTable that you Fill from the DataAdaper up front.
You can also add ColumnMappings that will help make sure that the data ends up in the right place:
http://msdn.microsoft.com/library/en...mnmappings.asp
(Once in one of these MSDN links, you can use the categories they're in to get a ton more information.)
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
02-09-2006, 08:08 PM #9
silenuz,
i had found out that your coding is under VS2005 with .NET framework version 2... but your code can be used if
i install framework version 2... by the way, can framework version 2 support VS2003?
wayneph,
thanks for your advice
I'm pretty sure there is no support in 2003 for .Net V2 but with MS giving away copies of the express editions of
VS 2005 you could always download it and try it. It runs side by side with 2003, but I loing since uninstalled
2003, never really used it anyway,waste of company expenses as I held out using VB6 till a few months ago,
and I figured if I was finally going to take the .Net plunge I would just start with 2005.
3 of 4 26/01/2013 13:04
import csv file into datagrid - Xtreme Visual Basic Talk http://www.xtremevbtalk.com/showthread.php?t=251869
Quote:
You can also add ColumnMappings that will help make sure that the data ends up in the right place:
http://msdn.microsoft.com/library/en...mnmappings.asp
(Once in one of these MSDN links, you can use the categories they're in to get a ton more information.)
wayneph,
i had create the datatable but how can i pass the data into it while the csv file still haven't read... once it read,
the value that i wants had become null...
as i know that we need to assign the data into the datatable...
how can i pass the data direct from csv into the datatable?
Posting Rules
BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Forum Rules
Free Publications
Programmers Heaven C# School Book -Free 338 Page eBook Japan Anime Tours
The Programmers Heaven C# School book covers the .NET framework and the C# language. Tour major anime attractions for the ultimate otaku
subscribe experience!
www.inspiredsteps.o rg/anime
Microsoft 70-305 Developing and Implementing Web Apps with VB .NET and VS .NET SE Special
Edition Practice Exam Kaos tentang Indonesia
Bahan Katun Enak, Nasionalis Gaul dari
ExamForce practice exams save IT professional's time and money by focusing their study time on the Kementerian Desain R.I
areas they need help most. distrokdri.com
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and
running in no time..
subscribe
-->
4 of 4 26/01/2013 13:04