注册 登录
编程论坛 VFP论坛

VFP SPT保存到SQL数据,字段很多空格,这个有办法处理吗?

ljb8864 发布于 2023-12-20 09:32, 315 次点击
VFP SPT保存到SQL数据,字段很多空格,这个有办法处理吗?


如:cnn=SQLCONNECT("northwind")
SQLEXEC(cnn,"select categoryid as id ,categoryname,description from categories","mycursor")
SELECT mycursor
CURSORSETPROP("Tables","categories","mycursor")
CURSORSETPROP("KeyFieldList","id","mycursor")
CURSORSETPROP("UpdatableFieldList" ,"id,categoryname,description","mycursor")
CURSORSETPROP("UpdateNameList","id categories.categoryid,categoryname categories.categoryname,"+ "description categories.description","mycursor")
CURSORSETPROP("SendUpdates" ,.t.,"mycursor")
CURSORSETPROP("WhereType" ,3)

Visual FoxPro的所有的SQL Pass Though功能
保存时,字段上有很我空格。

[此贴子已经被作者于2023-12-20 09:35编辑过]

4 回复
#2
easyppt2023-12-20 10:35
VFP 的 cursor 字符型的字段类型 调整为 V,即可,CA很容易。
SPT的自动更新模式我很少用,不知道能不能设置cursor类型,如果能,改成V,就可以了。
#3
ljb88642023-12-20 12:05
回复 2楼 easyppt
local lcConnString, ;
loCursor as CursorAdapter, ;
laErrors[1] lcConnString = 'driver=SQL Server;server=(local);' + ;
      'database=Northwind;uid=sa;pwd=;trusted_connection=no'
* 把这里的密码改成你自己的数据库中密码
loCursor = createobject('CursorAdapter')
with loCursor
  .Alias = 'Customers'
  .DataSourceType = 'ODBC'
  .DataSource = sqlstringconnect(lcConnString)
  .SelectCmd = "select CUSTOMERID, " + ;
      "COMPANYNAME, CONTACTNAME from CUSTOMERS " + ;
      "where COUNTRY = 'Brazil'"
  .KeyFieldList = 'CUSTOMERID'
  .Tables = 'CUSTOMERS'
  .UpdatableFieldList = 'CUSTOMERID, COMPANYNAME, ' + ;
      'CONTACTNAME'
  .UpdateNameList = ;
      'CUSTOMERID CUSTOMERS.CUSTOMERID, ' + ;
      'COMPANYNAME , ' + ;
      'CONTACTNAME CUSTOMERS.CONTACTNAME'
  if .CursorFill()
     browse
  else
     aerror(laErrors)
     messagebox(laErrors[2])
  endif
  .CursorFill()
endwith


CA还没有使用过,是这样吗?但是字段类型怎么改?
#4
ljb88642023-12-20 12:48
* 只是一个指向 DataEnvironment 对象的指针.
 myde=Createobject("Data1")
 Thisform.DataEnvironment=myde
 myde.ADDOBJECT("demoname", "demo")
 &&myde.demoname.selectcmd="select top 10 * from ................"
 myde.demoname.selectcmd=comSql

 
 * 在 LOAD 开始时打开表.
 Thisform.DataEnvironment.OpenTables

  Thisform.DataEnvironment.CloseTables && 在 destroy 过程的结束处关闭表



Define Class Data1 As DataEnvironment && 数据环境类
 Name = "Dataenvironment"
 
 Top = 220
 Left = 1
 Width = 520
 Height = 200
 Datasource = .Null.
 DataSourceType = "ADO"

 Procedure BeforeOpenTables
 *** Select connection code: DO NOT REMOVE

 Local loConnDataSource
 loConnDataSource = Createobject('ADODB.Connection')
 ***<DataSource>
 
 &&loConnDataSource.ConnectionString = [Provider=SQLOLEDB.1;Password=cxy;Persist Security Info=True;User ID=sa;Ini] + ;
 && [tial Catalog=bussetup;Data Source=.;]
 
 loConnDataSource.ConnectionString = conString
 ***</DataSource>
 loConnDataSource.Open()
 This.Datasource = Createobject('ADODB.RecordSet')
 This.Datasource.CursorLocation   = 3  && adUseClient
 This.Datasource.LockType         = 3  && adLockOptimistic
 This.Datasource.ActiveConnection = loConnDataSource
 *** End of Select connection code: DO NOT REMOVE

 ENDPROC
 
Enddefine && 添加 Cursor 类对象

DEFINE CLASS demo as CursorAdapter
UseDeDataSource= .T.
 
SelectCmd="select * from ........."
 

CursorSchema ="ID I, 日期 T"
 

 

Alias = "demotable"
Flags = 0
KeyFieldList = "ID"
Tables = ".......D"
UpdatableFieldList = "................"
UpdateNameList = "......................."
UseCursorSchema = .T.
Name = "demo"


 Procedure Init
 *** Setup code: DO NOT REMOVE
 Local llReturn
 Do Case
 Case Not Pemstatus(This, '__VFPSetup', 5)
  This.AddProperty('__VFPSetup', 0)
 Case This.__VFPSetup = 1
  This.__VFPSetup = 2
 Case This.__VFPSetup = 2
  This.__VFPSetup = 0
  Return
 Endcase
 Set Multilocks On
 llReturn = DoDefault()
 *** End of Setup code: DO NOT REMOVE

 *** Setup code: DO NOT REMOVE
 If This.__VFPSetup = 1
  This.__VFPSetup = 2
 Endif
 Return llReturn
 *** End of Setup code: DO NOT REMOVE

 Endproc
 Procedure AutoOpen
 *** Setup code: DO NOT REMOVE
 If Not Pemstatus(This, '__VFPSetup', 5)
  This.AddProperty('__VFPSetup', 1)
  This.Init()
 Endif
 *** End of Setup code: DO NOT REMOVE

 Endproc


ENDDEFINE

[此贴子已经被作者于2023-12-20 12:51编辑过]

#5
csyx2023-12-20 17:20
CA 类有 MapVarchar 属性可以设置
1