Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert-Update-Delete to SQLCE from VFP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
MS SQL Server CE
Application:
Desktop
Divers
Thread ID:
01438635
Message ID:
01438661
Vues:
46
>Something like (NOT TESTED!)
>
>* This script handles the ADO Connection and uses a CursorAdapter object
>* to retrieve data to a cursor.
>
>Public oCA As CursorAdapter
>Local oConn      As ADODB.Connection
>Local oRS        As ADODB.Recordset
>Local oComm      AS ADODB.Command
>Local oException As Exception
>Local cConnString
>
>* Handle connections - insert connection code
>cConnString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"+;
>	"Data Source=D:\Depomatik.sdf"
>Try
>	oConn  = Createobject('ADODB.Connection')
>
>	* Ensure that you handle userid and password if not
>	* specified in connection string.
>	*   ex. oConn.Open(cConnString, userid, password)
>	oConn.Open(cConnString)
>        oComm = Createobject("ADODB.Command")
>        oComm.ActiveConnection = oConn
>
>
>	oRS = Createobject("ADODB.Recordset")
>	oRS.Datasource.CursorLocation = 3   &&adUseClient
>	oRS.Datasource.LockType = 3   &&adLockOptimistic
>	oRS.ActiveConnection = oConn
>
>	oCA=Createobject("CursorAdapter")
>	oCA.DataSourceType = "ADO"
>	oCA.Datasource     = oRS
>	oCA.MapBinary      = .T.
>	oCA.MapVarchar     = .T.
>	oCA.SendUpdates    = .T.
>	oCA.KeyFieldList   =  ??????????????????????????????????? && Put the Key Field list here
>	oCA.WhereType      =  1 && Key Fields
>
>	oCA.Alias                    = "CARI"
>	oCA.SelectCmd                = "SELECT * FROM CARI"
>	oCA.InsertCmdDataSourceType  = "ADO"
>	oCA.UpdateCmdDataSourceType  = "ADO"
>	oCA.DeleteCmdDataSourceType  = "ADO"
>	oCA.RefreshCmdDataSourceType = "ADO"
>
>	oCA.InsertCmdDataSource      = oComm
>	oCA.UpdateCmdDataSource      = oComm
>	oCA.DeleteCmdDataSource      = oComm
>	oCA.RefreshCmdDataSource     = oComm
>
>
>	If !oCA.CursorFill(.f.,0,-1,oComm)
>           * Replace with error code here
>           Local laError
>           Dimension laError[1]
>           Aerror(laError)
>           Messagebox(laError[2])
>	Else
>           * Replace with user code here. Code below allows for
>           * you to edit and send updates to the backend.
>           Local laFlds,lcStr,lnFldCount,i
>           Dimension laFlds[1]
>           lnFldCount=Afields(laFlds)
>           lcStr=""
>           lcStr2 = ""
>           For i = 1 To lnFldCount
>               lcStr  = lcStr  + laFlds[m.i,1] +  ","
>               lcStr2 = lcStr2 + laFlds[m.i,1] +  "CARI."+laFlds[m.i,1]+","
>           Endfor
>           oCA.UpdatableFieldList = LEFT(lcStr , LEN(lcStr )-1) && To remove last comma
>           oCA.UpdateNameList     = LEFT(lcStr2, LEN(lcStr2)-1) && To remove last comma
>
>           BROWSE NORMAL NOWAIT
>	Endif
>
>Catch To oException
>	* Replace with exception handling code here
>	Messagebox(oException.Message)
>Endtry
>
>* Add user code here.
>* Note: cursors created by CursorAdapter object are closed when object is released.
>
>Again, that is NOT tested!
>
>
>
>
>>Hi All,
>>i want to improve below codes generated from DataExplorer for Insert-Update-Delete to SQLCE how would be your suggestions.
>>
>>
>>
>>
>>* This script handles the ADO Connection and uses a CursorAdapter object
>>* to retrieve data to a cursor.
>>
>>Public oCA As CursorAdapter
>>Local oConn As ADODB.Connection
>>Local oRS As ADODB.Recordset
>>Local oException As Exception
>>Local cConnString
>>
>>* Handle connections - insert connection code
>>cConnString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"+;
>>	"Data Source=D:\Depomatik.sdf"
>>Try
>>	oConn  = Createobject('ADODB.Connection')
>>
>>	* Ensure that you handle userid and password if not
>>	* specified in connection string.
>>	*   ex. oConn.Open(cConnString, userid, password)
>>	oConn.Open(cConnString)
>>
>>	oRS = Createobject("ADODB.Recordset")
>>	oRS.Datasource.CursorLocation = 3   &&adUseClient
>>	oRS.Datasource.LockType = 3   &&adLockOptimistic
>>	oRS.ActiveConnection = oConn
>>
>>	oCA=Createobject("CursorAdapter")
>>	oCA.DataSourceType = "ADO"
>>	oCA.Datasource = oRS
>>	oCA.MapBinary = .T.
>>	oCA.MapVarchar = .T.
>>
>>	oCA.Alias = "CARI"
>>	oCA.SelectCmd = "SELECT * FROM CARI"
>>	oCA.UpdateCmd = ""
>>	oCA.InsertCmd = ""
>>	oCA.DeleteCmd = ""
>>
>>	If !oCA.CursorFill()
>>		* Replace with error code here
>>		Local laError
>>		Dimension laError[1]
>>		Aerror(laError)
>>		Messagebox(laError[2])
>>	Else
>>		* Replace with user code here. Code below allows for
>>		* you to edit and send updates to the backend.
>>		Local laFlds,lcStr,lnFldCount,i
>>		Dimension laFlds[1]
>>		lnFldCount=Afields(laFlds)
>>		lcStr=""
>>		For i = 1 To lnFldCount
>>			lcStr = lcStr + laFlds[m.i,1] +  ","
>>		Endfor
>>		oCA.UpdatableFieldList = lcStr
>>		BROWSE NORMAL NOWAIT
>>	Endif
>>
>>Catch To oException
>>	* Replace with exception handling code here
>>	Messagebox(oException.Message)
>>Endtry
>>
>>* Add user code here.
>>* Note: cursors created by CursorAdapter object are closed when object is released.
>>
error on line
Messagebox(laError[2])
Function Argument Value,type or count is invalid !

normally messagebox can show this array value but now i am getting error :(
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform