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...






Forums » .NET » .NET »

Display .xls file contents in a textbox using vb.net


Posted Date: 03 Nov 2009      Posted By: anujj      Member Level: Bronze     Points: 1   Responses: 1



hi all,
i have a problem displaying excel spreadsheet contents in a textbox which i use as a preview pane. when i browse a xls file , all the contents are to be displayed in that textbox. i have successfully displayed the contents in a datagridview, but now i want it on a textbox.I hope there is a way of doing so.
please help
thanks





Responses

Author: anujj    03 Nov 2009Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

the following is my code i have collected so far to display xls/xlsx in a datagrid. WHAT SHOULD I DO TO PREVIEW THE EXCEL FILE CONTENTS IN A TEXTBOX?

CODE:
Dim ds As New DataSet
Dim result As DialogResult = OpenFileDialog1.ShowDialog()
Try
Dim wbPath As String
If result = DialogResult.OK Then



Dim objFi As New FileInfo(OpenFileDialog1.FileName)

wbPath = OpenFileDialog1.FileName

'Dim connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & wbPath & ";" & "Extended Properties=Excel 12.0"

Dim sConnectionString As String = "provider=microsoft.ACE.oledb.12.0;" _
& "data source=" & wbPath _
& ";" & "extended properties=excel 12.0;"





ds.Clear()





Dim strSQL As String = "SELECT * FROM [Sheet1$]"
Dim excelConnection As OleDbConnection = New OleDbConnection(sConnectionString)
excelConnection.Open()

Dim dbCommand As OleDbCommand = New OleDbCommand(strSQL, excelConnection)
Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter(dbCommand)



dataAdapter.Fill(ds, "dTable")
DataGridView1.DataSource = ds.Tables("dTable").DefaultView

' disposing used objects
ds.Dispose()
dataAdapter.Dispose()
dbCommand.Dispose()
excelConnection.Close()
excelConnection.Dispose()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try



Post Reply
You must Sign In to post a response.
Next : Employee entry form using asp with c# urgent
Previous : SQL Query
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use