Results 1 to 2 of 2

Thread: Import excel cell value into window form application text box

  1. #1
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2015

    Import excel cell value into window form application text box

    Hi, I've created a windowsform application into using excel as a data base. one the button click even all the filled data export into the excel file. now I want on the same time one particular excel value come into the windows form defined text box.

    below is the code. please modify the same.

    Imports System.Data.OleDb
    Public Class Form1

    Dim Cn As New OleDbConnection
    Dim cm As New OleDbCommand

    Private Sub BtnSave_Click(sender As System.Object, e As System.EventArgs) Handles BtnSave.Click

    Cn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=C:\Users\rajkumar.shukla\Desktop\Testing\te sting.xlsm;extended properties=excel 8.0"

    With cm
    .Connection = Cn
    .CommandText = "insert into [testing$]values('" & TxtComp.Text & "','" & TxtDep.Text & "','" & TxtVer.Text & "','" & TxtDat.Text & "', '" & TxtIni.Text & "','" & TxtSig.Text & "','" & TxtSub.Text & "','" & Txtyear.Text & "')"

    End With


    MsgBox("Reference Number Generate Successfully", MsgBoxStyle.Information, Text)

    End Sub
    End Class

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Sydney, Australia
    You clearly already know how to work with the Excel file as a database. In order to retrieve data from it you would do just as you would for any other database. You would create and open a connection and execute a command. ExecuteScalar would be the method to call if you want just one value or you can call ExecuteReader to get multiple values from one or more rows.

    That said, I really must suggest NOT using Excel as a database because it is NOT a database. If you have data in Excel files and must use them as a data source then so be it but if it's within your power to select a database for your app then at least use Access or maybe something better like SQLite, SQL Server CE or even SQL Server Express.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts