web 2.0

ASP.NET(vb.net) & Convert CSV To DataSet

ASP.NET(vb.net) & Convert CSV To DataSet - In this article we will example scripts ASP.NET how to read CSV file and convert to DataSet.

ShotDev Focus:
- ASP.NET(vb.net) & Convert CSV To DataSet

Example

AspNetCsvAdoDataSet.aspx

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
Dim dt As DataTable

'*** Csv to DataSet ***'
dt = CsvCreateDataSet.Tables(0)

'*** BindData to Repeater ***'
myRepeater.DataSource = dt
myRepeater.DataBind()
End Sub

'*** Convert CSV to DataSet ***'
Function CsvCreateDataSet() As DataSet
Dim objConn As New System.Data.OleDb.OleDbConnection
Dim objCmd As New System.Data.OleDb.OleDbCommand
Dim dtAdapter As New System.Data.OleDb.OleDbDataAdapter

Dim ds As New DataSet
Dim strConnString,strSQL As String

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&Server.MapPath("csv/") & _
";Extended Properties='TEXT;HDR=Yes;FMT=Delimited;Format=Delimited(,)'"

strSQL = "SELECT * FROM customer.csv"

objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd

dtAdapter.Fill(ds)

dtAdapter = Nothing
objConn.Close()
objConn = Nothing

Return ds   '*** Return DataSet ***'

End Function

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>CustomerID</th>
<th>Name</th>
<th>Email</th>
<th>CountryCode</th>
<th>Budget</th>
<th>Used</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%#Container.DataItem(0) %></td> <!--or <Container.DataItem("CustomerID")  -->
<td><%#Container.DataItem(1) %></td> <!--or <Container.DataItem("Name")  -->
<td><%#Container.DataItem(2) %></td> <!--or <Container.DataItem("Email")  -->
<td align="center"><%#Container.DataItem(3) %></td> <!--or <Container.DataItem("CountryCode")  -->
<td align="right"><%#Container.DataItem(4) %></td> <!--or <Container.DataItem("Budget")  -->
<td align="right"><%#Container.DataItem(5) %></td> <!--or <Container.DataItem("Used")  -->
</tr>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) & Convert CSV To DataSet
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.