473,624 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble Retrieving Excel Data using VB.NET 2003

Hi and thanks in advance for any assistance recieved,

There is most likely a simple solution to this as usual...

I am trying to access data from an Excell worksheet using ADO.

The problem is that the OleDbCommand does not seem to recognise the Date
parameter in the command string.

Code follows:

Dim dDate As Date = dtp1.Value

Debug.WriteLine (dDate & " is the selected date.")

Dim conn As New System.Data.Ole Db.OleDbConnect ion(sConn)
Try
conn.Open()
Dim dvResult As New System.Data.Dat aView
Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] = " &
dDate.ToShortDa teString, conn)

Dim ds As DataSet = New DataSet
Dim da As New OleDbDataAdapte r(cmd)
da.Fill(ds, "DailyAnalysis" )

'Debugging routine
For Each dr As DataRow In ds.Tables(0).Ro ws

Debug.WriteLine (System.String. Format("{0},{1} ,{2},{3},{4},{5 },{6},{7},{8},{ 9},{10},{11},{1 2}," & _
"{13},{14}" , _
dr("DATE"), dr("FACT"), dr("MACH"), dr("PROFILE"),
dr("FORMULA"), dr("LENGTH"), _
dr("QUANTITY") , dr("TOTAL MTRS"), dr("WPM"),
dr("TOTAL KG"), dr("BALANCE"), dr("STATUS"), _
dr(12), dr("CODE"), dr("Category")) )
Next

dvResult = New DataView(ds.Tab les(0))
DataGrid1.DataS ource = dvResult
....

If I Use this statement:

Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] IS NOT NULL,
conn)

I get to populate my DataGrid but obviously with data that I dont require.

Any suggestions please?
Mar 19 '06 #1
2 1487
Andy,

I was already stopping when you wrote that you did it in Ado. Don't tell
that you use ADO when it is ADONET. The differences are the same as between
a car and a plane.

I have no answer for you , however dates are always a pain. In your case I
would try it with an OleDB parameter.

Have a look at this sample for that.
http://www.vb-tips.com/default.aspx?...3-eb8b44af0137

I hope this helps,

Cor

"AndyJ" <An***@discussi ons.microsoft.c om> schreef in bericht
news:46******** *************** ***********@mic rosoft.com...
Hi and thanks in advance for any assistance recieved,

There is most likely a simple solution to this as usual...

I am trying to access data from an Excell worksheet using ADO.

The problem is that the OleDbCommand does not seem to recognise the Date
parameter in the command string.

Code follows:

Dim dDate As Date = dtp1.Value

Debug.WriteLine (dDate & " is the selected date.")

Dim conn As New System.Data.Ole Db.OleDbConnect ion(sConn)
Try
conn.Open()
Dim dvResult As New System.Data.Dat aView
Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] = " &
dDate.ToShortDa teString, conn)

Dim ds As DataSet = New DataSet
Dim da As New OleDbDataAdapte r(cmd)
da.Fill(ds, "DailyAnalysis" )

'Debugging routine
For Each dr As DataRow In ds.Tables(0).Ro ws

Debug.WriteLine (System.String. Format("{0},{1} ,{2},{3},{4},{5 },{6},{7},{8},{ 9},{10},{11},{1 2},"
& _
"{13},{14}" , _
dr("DATE"), dr("FACT"), dr("MACH"), dr("PROFILE"),
dr("FORMULA"), dr("LENGTH"), _
dr("QUANTITY") , dr("TOTAL MTRS"), dr("WPM"),
dr("TOTAL KG"), dr("BALANCE"), dr("STATUS"), _
dr(12), dr("CODE"), dr("Category")) )
Next

dvResult = New DataView(ds.Tab les(0))
DataGrid1.DataS ource = dvResult
...

If I Use this statement:

Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] IS NOT NULL,
conn)

I get to populate my DataGrid but obviously with data that I dont require.

Any suggestions please?

Mar 19 '06 #2
Cor,

You are right ADONET - I did some digging and found the solution:

Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] = #" & dDate &
"#",conn)

Formatting of the dDate variable did the trick nicely.

Regards

"Cor Ligthert [MVP]" wrote:
Andy,

I was already stopping when you wrote that you did it in Ado. Don't tell
that you use ADO when it is ADONET. The differences are the same as between
a car and a plane.

I have no answer for you , however dates are always a pain. In your case I
would try it with an OleDB parameter.

Have a look at this sample for that.
http://www.vb-tips.com/default.aspx?...3-eb8b44af0137

I hope this helps,

Cor

"AndyJ" <An***@discussi ons.microsoft.c om> schreef in bericht
news:46******** *************** ***********@mic rosoft.com...
Hi and thanks in advance for any assistance recieved,

There is most likely a simple solution to this as usual...

I am trying to access data from an Excell worksheet using ADO.

The problem is that the OleDbCommand does not seem to recognise the Date
parameter in the command string.

Code follows:

Dim dDate As Date = dtp1.Value

Debug.WriteLine (dDate & " is the selected date.")

Dim conn As New System.Data.Ole Db.OleDbConnect ion(sConn)
Try
conn.Open()
Dim dvResult As New System.Data.Dat aView
Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] = " &
dDate.ToShortDa teString, conn)

Dim ds As DataSet = New DataSet
Dim da As New OleDbDataAdapte r(cmd)
da.Fill(ds, "DailyAnalysis" )

'Debugging routine
For Each dr As DataRow In ds.Tables(0).Ro ws

Debug.WriteLine (System.String. Format("{0},{1} ,{2},{3},{4},{5 },{6},{7},{8},{ 9},{10},{11},{1 2},"
& _
"{13},{14}" , _
dr("DATE"), dr("FACT"), dr("MACH"), dr("PROFILE"),
dr("FORMULA"), dr("LENGTH"), _
dr("QUANTITY") , dr("TOTAL MTRS"), dr("WPM"),
dr("TOTAL KG"), dr("BALANCE"), dr("STATUS"), _
dr(12), dr("CODE"), dr("Category")) )
Next

dvResult = New DataView(ds.Tab les(0))
DataGrid1.DataS ource = dvResult
...

If I Use this statement:

Dim cmd As New System.Data.Ole Db.OleDbCommand ( _
"SELECT * FROM [DailyAnalysis$] WHERE [Date] IS NOT NULL,
conn)

I get to populate my DataGrid but obviously with data that I dont require.

Any suggestions please?


Mar 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5025
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table. Before I iterate through the recordset I instruct the browser that the content type is Excel using the following line: (Response.ContentType = "application/vnd.ms-excel") This works fine with Excel 2003 but with older versions (I tested Excel...
0
4186
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS Excel 2003, I have VBA code that creates and executes queries using the Access database, and returns the results to an Excel sheet. The first time the query is executed, results are returned to Excel in usually less than 10 seconds. However, if the...
17
6331
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
3
4122
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the error: <FileName> cannot be accessed. The file may be read-only, or you may be trying to access a read-only location. Or, the server the document is stored on may not be responding.
3
1941
by: ineedahelp | last post by:
Hi and HELP!, I am using Excel and Access 2003. I am trying to create a link to an excel spreadsheet and append the data from a specific sheet called "PEJ". My error is runtime error 3125 "PEJ$" is not a valid name. When I perform these tasks manually it works...any help? Oh, I prefer to link because the spreadsheet data will change quite frequently and I will be performing this function on multiple sheets. Dim db As Database Dim...
10
8145
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine and excel is closed. But there are some commented lines: //xlSeries.XValues = xlWs.get_Range("B2", "B4"); // makes com objects, but which...
4
2124
by: indrajith_varma1 | last post by:
Hi I am working on an application to retrieve data from excel and insert into SQL Server database. Yesterday, I faced a strange problem. In a column in the excel, if 1st 8 rows are number, then as soon as an alphanumeric or string value is encountered, the string becomes null and put into the data set. IMEX property of the excel connection object is set as 1. Is there any solution in the .NET code to fix this issue? In anticipation...
4
3975
by: =?Utf-8?B?THluZXJz?= | last post by:
Hello All, We have a VB.NET application writen using VS 2003. This application apens an excel file from a vendor, reads the data and performs whatever functions it needs. We recently upgraded our sytems to Excel 2003 from Excel 2000. Our application started erroring out because it was having a problem with opening the Excel file. From troubleshooting, the exact problem is in Excel 2003, it does not like the sheet name (even though the...
3
2538
by: keirnus | last post by:
hello, been searching for a solution on this but all i get are advices for importing data from excel directly to MS Access DB. my case here is different...the sheet in Excel file is not ready for importing... the data are scattered from different cells from different sheets... this is because these sheets are automated for their own role... i just need to get data from a certain cell using VBA den save the data to MS Access DB.
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.