|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unable to read data from excel file
Hi,
I am using an vb script to connect to excel file and reading a data from it , some of the fileds which are without having dot for example ( Name Address etc ) at hearder row i am able to read but the fileds are like ( 1111111_AB.Test ) unable to read with vb script if i remove "_" and "dot" in between of this field then i am able read please suggest , the code can be found below : Code:
Set objConn = CreateObject("ADODB.Connection")
strConnection = "DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=1;HDR=Yes;DBQ=" & PathName
objConn.Open strConnection
'objConn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
' "DriverId=790;" & _
' "Dbq=" & PathName &";" & _
' "DefaultDir=B:\temp"
'dim dd,ee
Set objRS=CreateObject("ADODB.recordset")
' Write the SQL Query
objRS.open "SELECT * FROM [Sheet1$A1:CQ303]", objConn
do until objRS.EOF
dim mname, maddress, mchr, m_type, m_score, m_the, mar, m_allq, m_log, m_le, m_cns, m_allcalls, sub_id, de_date, de_time,Pos
sub_id = subid
de_date = SDT
de_time = STime
MsgLog("Database Connected " & SDT & " | " & STime )
MsgLog(objRS("AGT"))
mname = objRS("Name")
maddress = objRS("Address")
mchr = objRS("Chr")
m_type = objRS("AGT")
__________________
SELF REALIZATION IS THE FIRST ENCOUNTER WITH REALITY.- Sahajayoga.org |
|
#2
|
||||
|
||||
|
--moved to the Windows Scripting forum.
what do you mean by "unable to read"? what error you get and on what exact line of code? |
|
#3
|
|||
|
|||
|
unable to read is shows an error is below :
Item cannot be found in the collection corresponding to the request name or ordinal ADODB.Recordset but the filed is there if i remove the dot and _ it works. Quote:
Please suggest Last edited by digitaldxb : December 29th, 2006 at 02:02 AM. |
|
#4
|
||||
|
||||
|
for the sake of debug, have such code:
Code:
If Not(objRS.EOF) Then
For x=0 To objRS.Fields.Count-1
MsgBox("field #" & (x+1) & " name: " & objRS.Fields(x).Name & ", value: " & objRS.Fields(x).Value)
Next
End If
do you see correct field names and values? |
|
#5
|
|||
|
|||
|
Quote:
Thanks again for helping with good idea .... i used this script and found that its giving as # .... just replaced with # it worked thanks ..... any idea how to convert vbscript to ASP pages if any do let me know how to do it , I want to convert this whole script in asp and try to scan the csv or xls file via file uploading options so that user can upload files and it will scan and put the data in database. |
|
#6
|
||||
|
||||
|
no problem!
![]() that code is already ASP, except minor change - change any CreateObject to Server.CreateObject however I suspect MsgLog function will already need more changes, post its code if you need help converting it. |
|
#7
|
||||
|
||||
|
Shadow is right. ASP supports VBS natively. No need to convert anything.
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#8
|
||||
|
||||
|
Quote:
ASP VBScript has the Server, Request, Response, Application and Session while "Windows VBScript" (any better name?) has none of these but rather it has WScript object with all the input/output support. so it means that any code involving these must be changed when converting. |
|
#9
|
||||
|
||||
|
Quote:
VBScript was designed as a web language to compete with such languages as JavaScript. It was designed to be a client-side web scripting language. It is the same language used by the WSH interpreter. The Server, Request, Response, Application and Session are objects only available within the browser environment. Likewise, the Wscript, TextStream, WshArguments, WshCollection, WshEnvironment, WshNetwork, WshShell, WshShortcut, WshSpecialFolders, and WshUrlShortcut objects are only available from within the WSH environment. But the language is the same. VBA is a form of VBScript for use in macros. This is the variation that is packaged in Microsoft Word and Excel among others. While it's structure and syntax is very similar there are minor differences and a limited feature set. Remember, all interpreted (scripting) languages are environmental. The use and performance is completely dictated by the environment in which it's run. Furthermore, VBS is object-oriented. Therefore, it relies solely on the objects available to it. Several objects are not supported by browsers for obvious security reasons just like several objects aren't supported by WSH for lack of any real purpose. |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Unable to read data from excel file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|