Click here to Skip to main content
13,141,838 members (62,995 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Is there a simple way of importing numeric data from a single cell in excel (2003) into
a textbox in a visual basic form?
Posted 20-Jul-10 6:26am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can Take all the data from the excel into datagrid view and Select the perticular cell of datagrid view and take cell data to textbox..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Ok I would create a class to handle the OleDB Connection(I'm assuming you're using VB .NET), so that you can reuse code; lets assume that you have an Excel Database with Names and Ages of people and you would like your Textbox to display the age of the selected person.

Public Class ExcelReader
         Private Function ConnString(ByVal str As String) As String
                 'str is the Path to the Excel File.
              Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
              + str + ";Extended Properties=""Excel 8.0;HDR=Yes"""
         End Function
         Public Sub RetrieveRecord(ByVal str As String, ByVal Name As String)
               'str is again the Path to the Excel File, and Name is the Name
               'you would like to find the age for.
              Dim Conn As New OleDBConnection
              Dim Comm As New OleDBCommand
              Dim DReader As OleDBDataReader
              Conn.ConnectionString = ConnString(str)
              Comm.Connection = Conn
              Comm.CommandText = "Select * From [Sheet1$] Where Name =" & Name
                DReader = Comm.ExecuteReader
                txtDisplayAge.Text = DReader.GetString(1)
                 'OleDBDataReader.GetString() takes a zero based index
                 'to reference the column you would like to retrieve
                 'and it also reads the field as a string so that there
                 'is no need to use the .ToString() Method.
                 'Close the OleDBDataReader Object
                 'Close the Connection
               Catch ex As Exception
               End Try
            End Sub

I hope this helps you out.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

use ur textbox where i use dd,mm,yyyy veriable

Dim app As Excel.Application
Dim wb As Excel.Workbook
Dim sheet As Excel.Worksheet
Dim var As Variant
Set app = New Excel.Application
Dim path As String
Set wb = app.Workbooks.Open(filepath)
Set sheet = wb.Worksheets.Item("JAN-2012")
Dim c As Integer
c = 2
With sheet
Dim lastrow As Integer
Do While .Cells(c, 1) <> ""
c = c + 1
End With
With sheet
Dim strdata As String
Dim i As Integer
Dim n As Integer
Dim dy1 As String
Dim dy As String
dy = DateTime.Date
dy1 = Format(dy, "dd/mm/yyyy")
For i = 2 To c - 1 Step 1
strdata = .Cells(i, 1)
dd = Format(strdata, "dd/mm/yyyy")
mm = Format(strdata, "mm/yyyy")
yy = Format(strdata, "yyyy")
dd1 = Format(dy1, "dd/mm/yyyy")
mm1 = Format(dy1, "mm/yyyy")
yy1 = Format(dy1, "yyyy")
If dd = dd1 Then
day = day + 1
End If
If mm = mm1 Then
month = month + 1
End If
If yy = yy1 Then
year = year + 1
End If
Next i
End With
Dim d1 As String
Dim mo1 As String
Dim ye1 As String
d1 = decimal_a(CStr(day))
mo1 = decimal_a1(CStr(month))
ye1 = decimal_a2(CStr(year))

Dim str As String
str = "M;" + d1 + ";" + mo1 + ";" + ye1 + ";;"
MsgBox str
'MsgBox day
'MsgBox month
'MsgBox year

Set sheet = Nothing
Set eb = Nothing
Set app = Nothing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 29 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100