ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help request for vb .net in excel (https://www.excelbanter.com/excel-programming/360632-help-request-vbulletin-net-excel.html)

kh

Help request for vb .net in excel
 
Hi evry one,
I have an excel file which contain group of cells from A2 to A10, those
cell values are changing almost each 10 seconds. Any one can help me how to
read those values in visual basic studio .net 2003. The excel file is always
open, I do not need to open it, I need to define this file and read the cell
values in my vb studio.
Help please.
Kh

campwes

Help request for vb .net in excel
 
kh,

You can use an OleDbDataReader (ADO.NET) and query the cells in your range:

Dim cmd As OleDbCommand = dbConn.CreateCommand()
cmd.CommandText = " select * from [Sheet1$A2:A10] "
rdr = cmd.ExecuteReader()

Use Console.WriteLine() or whatever to output the data where you need.

Ciao,

kh

Help request for vb .net in excel
 
Hi
Thank you for your time, appreciated.
Please write to me the complete code, because the lines you wrote are not
working. I am using visual studio vb 2005. Thank you.
Best Regards,
kh

"campwes" wrote:

kh,

You can use an OleDbDataReader (ADO.NET) and query the cells in your range:

Dim cmd As OleDbCommand = dbConn.CreateCommand()
cmd.CommandText = " select * from [Sheet1$A2:A10] "
rdr = cmd.ExecuteReader()

Use Console.WriteLine() or whatever to output the data where you need.

Ciao,


campwes

Help request for vb .net in excel
 
Here ya go:

Dim dbConn As OleDbConnection
Dim strConn As String
Dim strSQL As String
Dim rdr As OleDbDataReader

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=FileName.xls;Extended Properties=""Excel 8.0;IMEX=1"""
dbConn = New OleDbConnection(strConn)
dbConn.Open()

Dim cmd As OleDbCommand = dbConn.CreateCommand()
cmd.CommandText = " select * from [Sheet1$A2:A10] "
rdr = cmd.ExecuteReader()

Let me know if you need help with how to output the data from the query.

Cheers,



kh

Help request for vb .net in excel
 
Hi
Yes please let me know how to query data. For example, after reading data
A2:A10 , I wish to paste them in cells H2:H10 same sheet. I wish to know each
item of theses data as array, to be manipulated easily.
Many thanks for your time.
Best Regards,
kh

"campwes" wrote:

Here ya go:

Dim dbConn As OleDbConnection
Dim strConn As String
Dim strSQL As String
Dim rdr As OleDbDataReader

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=FileName.xls;Extended Properties=""Excel 8.0;IMEX=1"""
dbConn = New OleDbConnection(strConn)
dbConn.Open()

Dim cmd As OleDbCommand = dbConn.CreateCommand()
cmd.CommandText = " select * from [Sheet1$A2:A10] "
rdr = cmd.ExecuteReader()

Let me know if you need help with how to output the data from the query.

Cheers,



byronem

Help request for vb .net in excel
 
kh,

Unfortunately, you'll need to use VBA or macros to do what you want.
Selects are easy with ADO.NET, but inserts are another matter altogether. I
have no idea how to do that. Try posting to one of the VBA boards. Good
luck!

"kh" wrote:

Hi
Yes please let me know how to query data. For example, after reading data
A2:A10 , I wish to paste them in cells H2:H10 same sheet. I wish to know each
item of theses data as array, to be manipulated easily.
Many thanks for your time.
Best Regards,
kh

"campwes" wrote:

Here ya go:

Dim dbConn As OleDbConnection
Dim strConn As String
Dim strSQL As String
Dim rdr As OleDbDataReader

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=FileName.xls;Extended Properties=""Excel 8.0;IMEX=1"""
dbConn = New OleDbConnection(strConn)
dbConn.Open()

Dim cmd As OleDbCommand = dbConn.CreateCommand()
cmd.CommandText = " select * from [Sheet1$A2:A10] "
rdr = cmd.ExecuteReader()

Let me know if you need help with how to output the data from the query.

Cheers,




All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com