This is what I have so far...and yes it works importing the excel table to vfp.
[code]SET TALK OFF
LOCAL lcXLBook AS STRING, lnSQLHand AS INTEGER, ;
lcSQLCmd AS STRING, lnSuccess AS INTEGER, ;
lcConnstr AS STRING
CLEAR
lcXLBook = [C:\GLJEascTest.xls]
lcConnstr = [Driver=] + ;
[{Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};] + ;
[DBQ=] + lcXLBook
IF !FILE( lcXLBook )
? [Excel file not found]
RETURN .F.
ENDIF
*-- Attempt a connection to the .XLS WorkBook.
*-- NOTE: If the specified workbook is not found,
*-- it will be created by this driver! You cannot rely on a
*-- connection failure - it will never fail. Ergo, success
*-- is not checked here. Used FILE() instead.
lnSQLHand = SQLSTRINGCONNECT( )
*-- Connect successful if we are here. Extract data...
lcSQLCmd = [SELECT * FROM "SHEET1$"]
lnSuccess = SQLEXEC( lnSQLHand, lcSQLCmd, [xlResults] )
? [SQL Cmd Success:], IIF( lnSuccess > 0, 'Good!', 'Failed' )
IF lnSuccess < 0
LOCAL ARRAY laErr[1]
AERROR( laErr )
? laErr(3)
SQLDISCONNECT( lnSQLHand )
RETURN .F.
ENDIF
*-- Show the results
SELECT xlResults
BROWSE NOWAIT
SQLDISCONNECT( lnSQLHand )[/code]
> >
> > The connection to excel is unfortunately manual when I tried coding the connection it always failed.
> >
> > The other problem I have now is parsing the first excel column to remove the hyphens. It is currently loading into vfp as a memo field.
> >
> > I found this but I am not sure where to place the code :SEMyString = Replace(MyString, "-","")
> > ( all this code is running from a command button click event)
>
> hi Blair Lawrence
>
> I have the same problem as u..
> It is currently loading into vfp as a memo field.
> Do you know how do i change it to normal table field?
>
>
> Thank you!
Hi Shi,
I was unsuccessful with this strategy. My only way achieve a solution for the task at hand was to bypass VFP and create an excel program that connected to our MS SQL server and upload the data using a click event with
VB.NET.
I hope you find a solution.
Good Luck!
Cheers,
Blair