C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Showing Data From Excel Using OLEDB


Posted Date: 21 Oct 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Gopal Singh RathoreMember Level: Silver    
Rating: 1 out of 5Points: 10



------------------
Code for Test.ASPX
------------------




<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table style="position: relative">
<tr>
<td style="height: 21px; padding-left: 5px;" colspan="2" align="left">
Customer Information.....</td>
</tr>
<tr>
<td style="padding-left: 5px; height: 21px;" align="left">
Name:</td>
<td style="padding-left: 5px; height: 21px;" align="left">
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></td>
</tr>
<tr>
<td style="padding-left: 5px; height: 21px;" align="left">
Address</td>
<td style="padding-left: 5px; height: 21px;" align="left">
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td>
</tr>
<tr>
<td style="padding-left: 5px; height: 21px;" align="left">
</td>
<td style="padding-left: 5px; height: 21px;" align="left">
<asp:Button ID="Button1" runat="server" Text="Submit" /> <asp:Button ID="Button2"
runat="server" Style="position: relative" Text="Reset" /></td>

</tr>
</table>

</div>
<br />
<br />

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Style="position: relative"
Width="125px">
</asp:DetailsView>
</form>
</body>
</html>






-----------------

Code For Test.ASPx.VB

-----------------



Imports System.Data
Imports System.Data.DataSet
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Class test
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' Connect to the Excel Spreadsheet
Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("CustomerInformation.xls") & ";" & _
"Extended Properties=Excel 5.0;"

' create your excel connection object using the connection string
Dim objXConn As New OleDbConnection(ConnStr)
objXConn.Open()

' use a SQL Select command to retrieve the data from the Excel Spreadsheet
' the "table name" is the name of the worksheet within the spreadsheet
' in this case, the worksheet name is "Members" and is coded as: [Members$]

Dim objCommand As New OleDbCommand("SELECT * FROM [Sheet1$]", objXConn)

Dim objOledbDataAdapter As New OleDbDataAdapter()
objOledbDataAdapter.SelectCommand = objCommand

Dim objDataset As New DataSet()
objOledbDataAdapter.Fill(objDataset, "XLDATA")


DetailsView1.DataSource = objDataset.Tables(0).DefaultView
DetailsView1.DataBind()



objXConn.Close()



End Sub
End Class





Attachments

  • Display Records From Excel Using VB.NET (34281-211749-Showing-Data-From-Excel-Using-OlEDB.txt)


  • Responses

    Author: Abhay    22 Oct 2009Member Level: Diamond   Points : 1
    Hi Gopal Singh Rathore,

    Please follow code snippet submit guideline and put your code snippet in proper format.

    Thanks,
    Abhay
    Editor in DNS


    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Display Data from Excel To Details View in VB.NET  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Operators difference between VB & C#
    Previous Resource: Insert Records in Excel Sheet Using VB.NET
    Return to Discussion Resource Index
    Post New Resource
    Category: ASP.NET WebForms


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use