Geeks With Blogs

News


Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done
Public Function Convert(ByVal mFile As String, ByVal mTablename As String, ByVal delimiter As String) As DataSet
            ' The dataset to return
            Dim ds As New DataSet

            ' Open the file with a stream reader
            Dim sr As New StreamReader(mFile)

            ' Split the first line into the fields and add to string array called columns
            Dim columns As String() = sr.ReadLine().Split(delimiter.ToCharArray())

            ' Add the new Datatable to the DataSet
            ds.Tables.Add(mTablename)

            ' Cylcle the columns, adding those that do not exist yet and sequencing the ones that do
            For Each col As String In columns
                Dim added As Boolean = False
                Dim _next As String = ""
                Dim i As Integer = 0

                While Not added
                    ' Build the column name and remove any unwanted characters
                    Dim columnname As String = col + _next
                    columnname = columnname.Replace("#", "")
                    columnname = columnname.Replace("'", "")
                    columnname = columnname.Replace("&", "")
                    columnname = columnname.Replace("""", "")

                    ' See if the column already exists
                    If Not ds.Tables(mTablename).Columns.Contains(columnname) Then
                        ds.Tables(mTablename).Columns.Add(columnname)
                        added = True
                    Else
                        ' If it did exist then we increment the sequencer and try again
                        i = i + 1
                        _next = "_" + i.ToString()
                    End If
                End While
            Next


            ' Read the rest of the data in the file
            Dim allData As String = sr.ReadToEnd()

            ' Split off each row at the Carriage Return / Line Feed
            ' Default line ending in most windows exports
            ' You may have to edit this to match your particular file
            ' This will work for Excel, Access etc default exports.
            Dim rows As String() = allData.Split(vbCr.ToCharArray)

            ' Add each row to the Dataset
            For Each rowValue As String In rows

                ' Remove quotation field markers
                Dim row As String = rowValue.ToString().Replace("""", "")

                ' Split the row at the delimiter
                Dim items As String() = row.Split(delimiter.ToCharArray())


                ' Add the item to the dataset
                ds.Tables(mTablename).Rows.Add(items)

            Next

            ' Cleanup - Release StreamReader Resources
            sr.Close()
            sr.Dispose()

            ' Return the imported data
            Return ds

        End Function
Regards
Posted on Wednesday, October 28, 2009 4:33 PM Excel | Back to top


Comments on this post: CSV to DataSet

# cheap sale information
Requesting Gravatar...
Thanks!Be happy to recommend:
cheap uggs online store
http://www.cosycentral.com

discount puma shoes online store
http://www.pumaforever.com
Left by UGG Classic Boots on Nov 18, 2009 11:33 AM

# re: CSV to DataSet
Requesting Gravatar...
http://www.123nikeshoes.com | Nike shoes | Nike Shox | Shox Rival | 123nikeshoes.com
Left by 123nikeshoes.com on Mar 01, 2010 8:25 AM

# re: CSV to DataSet
Requesting Gravatar...
I think I am not good enough for this soft. I can not understand it.prom dresses
Left by GG on Mar 29, 2010 12:22 AM

# re: CSV to DataSet
Requesting Gravatar...
Thank you, very helpful to me these
Left by cheap cell phones on Apr 01, 2010 9:26 PM

# re: CSV to DataSet
Requesting Gravatar...
I think I am not good enough for this soft. I can not understand it.
Left by 220-601 on Apr 06, 2010 10:06 PM

# re: CSV to DataSet
Requesting Gravatar...
Very good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks
Left by free books on Apr 30, 2010 11:39 AM

# Ed Hardy swimwear
Requesting Gravatar...
www.clothshoe.com :Bikini designer swimwear including Ed Hardy swimwear and bikinis, seperate bikini tops and bottonand I love ordering from clothshoe,Inc because they have such fast and speedy delivery. My MBT sport shoes are so comfortable and they rock. http://www.clothshoe.com/
Left by sexy bikini sale on May 12, 2010 2:01 AM

# re: CSV to DataSet
Requesting Gravatar...
Very good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial.
Left by geo tv live on Jun 06, 2010 4:18 PM

# re: CSV to DataSet
Requesting Gravatar...
Very good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thank you very much.
Left by geo tv live on Jul 21, 2010 6:11 PM

# re: CSV to DataSet
Requesting Gravatar...
Thanks for your post. i have read.
Left by egoods on Aug 24, 2010 1:10 AM

# re: CSV to DataSet
Requesting Gravatar...
http://www.analsex2k.info | Anal Sex | Anal Porn | Anal Sex Videos | analsex2k.info
Left by anal sex on Sep 28, 2010 4:14 AM

# re: CSV to DataSet
Requesting Gravatar...
I like your blog curently we are looking for a part time article writer would you be interested?
Left by ugg classic Boots on Nov 04, 2010 1:31 AM

# re: CSV to DataSet
Requesting Gravatar...
I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing
Left by pre order cataclysm on Nov 11, 2010 7:04 PM

# lacoste shoes
Requesting Gravatar...
Dont wipe out hope if not as well a lot of men and women see your perspective, know you may have acquired a fan suitable the following who values what you’ve obtained to say along together with the way you’ve introduced yourself. Excellent on you!
Left by lacoste shoes on Nov 18, 2010 3:13 AM

# re: CSV to DataSet
Requesting Gravatar...
thanks buddy for the free computer books
Left by free books on Nov 22, 2010 12:35 PM

# re: CSV to DataSet
Requesting Gravatar...
Ok, how would i add your rss feed to my reader, sorry this is all new stuff for me so please be patient with me, thanks. Smile
Left by puma speed cat on Nov 24, 2010 5:43 AM

# re: CSV to DataSet
Requesting Gravatar...
You made some good points there. I did a search on the topic and found your blog.barbie oyunları thanks
Left by giysi giydirme oyunları on Nov 24, 2010 8:01 PM

# re: CSV to DataSet
Requesting Gravatar...
I was looking for this kind of information since a long time. You have finished my search by posting this link here. Any ways great post. Thanks for posting this here.
Left by Electric Garage Heaters on Dec 05, 2010 2:06 AM

# re: CSV to DataSet
Requesting Gravatar...
Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else,
Left by retro sneakers on Dec 18, 2010 1:20 AM

# re: CSV to DataSet
Requesting Gravatar...
Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read.I procrastinate alot and never seem to get something done
Left by white iphone 4 on Dec 22, 2010 7:45 PM

# re: CSV to DataSet
Requesting Gravatar...
a great post thank you
Left by wholesale designer clothing on Dec 22, 2010 8:57 PM

# re: CSV to DataSet
Requesting Gravatar...
There is clearly a bunch to identify about this. I think you made various good points in features also.
Left by iphone cases on Dec 26, 2010 8:56 PM

# re: CSV to DataSet
Requesting Gravatar...
Thank you so much for the great post. The only problem I got is that I don’t have a fast internet connection, so it is so difficult for me to open the amazon’s pages.
Left by Colon Cleanser ABC news on Jan 17, 2011 2:52 AM

# re: CSV to DataSet
Requesting Gravatar...
Thanks for a really simple explanation, its much appreciated.
Left by wva on Feb 10, 2011 6:20 AM

# lia james
Requesting Gravatar...
Interesting blog. It would be great if you can provide more details about it. Thanks you
Left by canadian flowers on Feb 25, 2011 5:39 AM

# re: CSV to DataSet
Requesting Gravatar...
I want to start by telling you that you have to be a very dedicated person with a full driving force to Websites for sale present in detail the program that you did. It was a great session and beautifully presented Turnkey Websites . Again, thank you for your presentation and my undying respect.
Left by Eugene on Mar 16, 2011 7:13 AM

# re: CSV to DataSet
Requesting Gravatar...
Thanks for a really simple explanation.
Left by rosetta stine on sale on Mar 16, 2011 11:44 PM

# DataSet
Requesting Gravatar...
Heya..thanks most important aspect of getting success.
Left by Prada Handbags on Mar 18, 2011 2:07 AM

# re: CSV to DataSet
Requesting Gravatar...
The information delivered in this article is of great concern and very shocking also. Very good work keep doing such things.
Left by website development on Mar 20, 2011 11:03 PM

# re: CSV to DataSet
Requesting Gravatar...
Let me congratulate you on your superb coding skills. Thank you and looking forward to seeing more great tutorial from you. I was actually in need for a CSV to DataSet demonstration. You seem to be very good with that.
Left by regcure on Apr 13, 2011 11:25 AM

# re: CSV to DataSet
Requesting Gravatar...
It's been a pleasure reading your post. I have bookmarked your website so that I can come back & read more in the future as well. Please do keep up the quality writing.
Left by India Tours on May 06, 2011 1:44 AM

# re: CSV to DataSet
Requesting Gravatar...
I had some problems with the same issue. Your example here helped me with solving that. The last line of the code is where I needed to modify something. Thanks.
Left by Phoenix Web design on May 16, 2011 11:16 AM

# re: CSV to DataSet
Requesting Gravatar...
As long as you have lives and can create the miracle of hands, there's no reason why you can when traveler, do the observer and the more have no cause for complaint about life. You find happiness?
Left by cheap Nike shox on May 26, 2011 3:38 AM

# re: CSV to DataSet
Requesting Gravatar...
Split off each row at the Carriage Return / Line Feed
' Default line ending in most windows exports
' You may have to edit this to match your particular file
' This will work for Excel, Access etc default exports.
Left by landscape canvas on Jun 08, 2011 7:16 AM

# re: CSV to DataSet
Requesting Gravatar...
I love reading through your blog, I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
Left by Volvo Turbo on Jun 23, 2011 1:55 AM

# re: CSV to DataSet
Requesting Gravatar...
Meditrustrx is best Cupid Pharmacy" North America 2011. provide erectile dysfunction pills
Left by Kevin on Jun 27, 2011 7:32 AM

# re:
Requesting Gravatar...
Useful information ..I am very happy to read this article..thanks for giving us this useful information. Fantastic walk-through. I appreciate this post.
Left by Awnings on Jul 11, 2011 5:41 AM

# re: CSV to DataSet
Requesting Gravatar...
I know this if off topic but I'm looking into starting my own blog and was wondering what all is needed to get setup? I'm assuming having a blog like yours would cost a pretty penny? I'm not very internet smart so I'm not 100% sure. Any suggestions or advice would be greatly appreciated. Kudos
Left by short love quotes on Aug 17, 2011 12:48 PM

# re: CSV to DataSet
Requesting Gravatar...
Well written ! i have to admit that it's very informative article. This really is another really very amazing and interesting publish. You've provided the publish that's proportional to the interest. Thank you for this publish.
Left by High Chair on Oct 03, 2011 11:47 PM

# re: CSV to DataSet
Requesting Gravatar...
Gee...!!! thanks so much for posting this lovely article i really enjoyed reading it
Left by cost effective seo company on Oct 04, 2011 12:04 PM

# re: CSV to DataSet
Requesting Gravatar...
Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks
Left by Helen Olsson on Oct 11, 2011 2:05 PM

# re: CSV to DataSet
Requesting Gravatar...
I just came across your blog and reading your beautiful words. I thought I would leave my first comment but I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
Helen Olsson
Left by science on Nov 18, 2011 9:51 AM

# re: CSV to DataSet
Requesting Gravatar...
I am very happy to read this article..thanks for giving us this useful information. and hank you for this publish.
Left by dentist medford or on Dec 03, 2011 11:47 AM

# georgetown homes for sale
Requesting Gravatar...
This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks
Left by homes for sale Georgetown, Texas on Feb 01, 2012 5:04 AM

# re: CSV to DataSet
Requesting Gravatar...
Good work! I always like to leave comments whenever I see something unusual or impressive. I think we must appreciate those who do something especial. Keep it up, thanks
Ingrit Ray

Left by live cricket on Feb 08, 2012 12:50 PM

# re: CSV to DataSet
Requesting Gravatar...
THANK U SO MUCH FOR THIS POST I LIKE THIS.
Left by solglasögon on Aug 07, 2012 3:24 AM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net