Load csv file to DataTable (VB) : CSV « ADO.net Database « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » ADO.net Database » CSV 
18. 43. 3. Load csv file to DataTable (VB)
<%@ Page Language="VB" Debug="true" %>
<script runat="server">

Sub Page_Load (Sender As Object, E As EventArgs)
  If Not IsPostBack Then
    Dim MyFileName as String
    Dim ObjectStreamReader as System.IO.StreamReader
    Dim ColorTable As New System.Data.DataTable("Colors")
    Dim fileRow() As String
    Dim dc As System.Data.DataColumn
    Dim dr As System.Data.DataRow

    dc = new System.Data.DataColumn("Hex",GetType(String))
    ColorTable.Columns.Add(dc)
    dc = new System.Data.DataColumn("String",GetType(String))
    ColorTable.Columns.Add(dc)

    MyFileName = Page.MapPath("Data.csv")

    Try
      ObjectStreamReader = new System.IO.StreamReader (MyFileName)
      While ObjectStreamReader.Peek() > -1
        dr = ColorTable.NewRow()
        fileRow = ObjectStreamReader.ReadLine().Split(",")
        dr(0= fileRow(0)
        dr(1= fileRow(1)
        ColorTable.Rows.Add(dr)
      End While
      Label1.Text = "Select a color:"    
      DropDownList1.DataSource = ColorTable
      DropDownList1.DataTextField = "String"
      DropDownList1.DataValueField = "Hex"
      DropDownList1.DataBind()

    Catch ObjectError as Exception
      Label1.Text = ObjectError.Message
      DropDownList1.Visible = False
    Finally
      If Not ObjectStreamReader Is nothing Then
        ObjectStreamReader.Close()
      End If
    End Try
  End If
End Sub
</script>
<html>
  <head>
  </head>
  <body>
    <form runat="server">
      <asp:Label id="Label1" runat="server"></asp:Label>
      <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    </form>
  </body>
</html>
18. 43. CSV
18. 43. 1. Create connection to csv text based database (C#)
18. 43. 2. Load csv file to DataTable (C#)
18. 43. 3. Load csv file to DataTable (VB)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.