Results 1 to 2 of 2

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

  1. #1
    rajkumar.shukla is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Feb 2015
    Posts
    8
    Reputation
    0

    Import excel cell value into window form application text box

    Hi, I've created a windowsform application into VB.net 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"
    Cn.Open()

    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 & "')"
    .ExecuteNonQuery()

    End With

    Cn.Close()

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

    End Sub
    End Class

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,801
    Reputation
    1705
    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.

Bookmarks

Posting Permissions

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