VFP9 picture SqlServer Image field of access processing

VFP9 of Cast Functions and Blob types for VFP lovers, really good news. For image data stored in the Image field SqlServer data tables, before the VFP9 process, it really is some trouble, now, to deal with the Cast and Blob much easier.

First to introduce it:

Cast () function:
the expression from one data type to another data type.
CAST ( eExpression AS cDataType [( nFieldWidth [, nPrecision ])] [NULL | the NOT NULL])
parameter
eExpression
specify a data expression, usually in a SQL statement you want to switch to another data type. eExpression may be a field, calculated field or other types of expressions.
cDataType
Specify legal name or indicate the target data type Hinako letters. cDataType may be equivalent to a valid data type or data type represent letters legal expression. 
Note: If cDataType specify an expression, you must use parentheses to cDataType expression specified in quotes.
Some field data type requirements nFieldWidth , nPrecision or both of the specified value.
nFieldWidth
specific data type field width. Visual FoxPro ignores the following data typesnFieldWidth : D, T, the I, the Y, L, M, G and W. If not specified nFieldWidth , default value is used, for example, by CREATE TABLE command values defined.
nPrecision
fractional digits for a particular data type. Visual FoxPro ignore the following data types nPrecision : C, D, T, the I, the Y, L, M, G, V, Q and W. If no numeric or Float specified data type nPrecision , zero (0), with no decimal. If nPrecision not does not contain a Double nPrecision , by default decimal SET DECIMALS value of the command set. If other types of data not specified nPrecision , default value is used, for example, a CREATE TABLE value of the command definition.
NULL | NOT NULL
to specify whether to allow null values in the field.
Note: If one or more fields may contain a null value, the maximum number of fields can be included in the table is reduced from 255 to 254.
If you do not specify NULLOr the NOT NULL , it inherits from the expression.

Binary Large Object (Blob) data type
to store a binary data of any kind, such as ASCII text, executable files (.exe) or a string of bytes with an indefinite length, using a large binary object data Types of. For the SQL Server stored image data, binary large object data types seem particularly useful.

Note that: The maximum number of characters in each string or memory variable is 16,777,184 bytes, so when dealing in the program generally allows maximum image file of about 16M.

Sample code:

Local lcImageName
lcImageName = AddBs(JustPath(Sys(16,1))) + Sys(2015)+'.jpg' && 设置本地文件名.
nCon=SqlStringConnect("Driver=SQL Server;Server=SERVER;Uid=sa;pwd=;database=DBSMarket") 
cSqlStr="Select Photo From T_BaseInfo Where ProID=1"
=SqlExec(nCon,cSqlStr,"CurTemp")
=SQLDisconnect(nCon)
=StrToFile(Cast(CurTemp.Photo As W), lcImageName, 0)
Use In ("CurTemp")
If File(lcImageName)
   ThisForm.Image1.Visible = .T. 
   ThisForm.Image1.Picture = lcImageName
Else
   ThisForm.Image1.Picture = lcImageName
   ThisForm.Image1.Visible = .F. 
EndIf
Erase [&lcImageName]

 

Guess you like

Origin www.cnblogs.com/hnllhq/p/12376104.html