如何将图片存到数据库中?

2016-01-29 16:14 100 1 收藏

如何将图片存到数据库中?,如何将图片存到数据库中?

【 tulaoshi.com - SQLServer 】

  如果你用的是sql server数据库!你不想用后台操作你可以看看这个
下面是对text的操作你可以看看
1. 写操作(WRITETEXT)
这里一般要用到的函数有TextPtr获得文本字段的指针,和TextVaild检验指针的有效性,@@RowCount判断返回记录的条数。
其基本方法是:用Textptr函数得到指针,判断其有效性,用Writetext写数据
函数说明:Textptr(字段名)。Writetext   tablename。Fieldname   @textptr(指针) [With Log]  data(数据)
例如:
Begin Tran
Declare  @Mytextptr   VarBinary(16)   
Select   @mytextptr=textptr(pr_info)
From  Pub_Info (updlock)
Where  pud_id=’9999’
IF  @Mytextptr Is Not Null
Writetext  pub_info.pr_info   @mytextptr   with log  ‘data’
Commit  Tran
2. 读操作
常用函数
PatIndex(‘%exp%’,var|fieldname。。)
Datalength()
@@TextSize 文本大小
SettextSize  N 设置文本大小
ReadText  {TableName。FieldName}  {@textptr}  Offet  Size   [HoldLock]
例如:
begin tran
Declare  @mytextptr  Varbinary(16),@Totalsize   int,@Readsize  int,@lastread  int
Set textsize 100
Select  @mytextptr=textptr(pr_info), @totalsize=datalength(pr_info)
@lastread=0,
@readsize= case  when  (textsize<datalength(pr_info) then  textsize
eles datalength(pr_info)
end
From  Pub_info
Where  Pub_id=’1622’
IF  @mytextptr Is  not Null  and @readsize0
While (@lastread<@totalsize)
ReadText  pub_info.pr_info   @mytextptr   @lastread   @readsize  holdlock
If (@@error<0)
  Break
Select @lastread=@lastread+@readsize
If ((@readsize+@lastread)@totalsize)
Select @readsize=@totalsize-@lastread
End
Commit  Tran
3.数据更新UpdateText
更新数据代替了写操作,其基本语法是:
UpdateText  Table_Name.Col_Name  Text_Ptr  Offest(偏移量)   Deleted_Length
[With Log] [Inserted_Data|Table_Name.Scr_Column_name   Str_Text_Ptr]
说明:
Offest:0说明从开头开始,Null表示你向当前内容追加数据。
Deleted_Length:0表示不删除任何内容,Null表示删除所有内容。
例如1(完全代替):
Declare  @mytextptr varbinary(16)
Begin tran
Select  @mytextptr=textptr(pr_infro)  from  pub_info(uplock)  where  pub_id=’9999’
If  @mytextptr is not null
Updatetext  pub_info.pr_infro  @mytextptr  0  null  with  log  “you are right”
Commit
例如2:
declare  @mytextptr  varbinary(16) ,@offest  int
Begin  tran
Select @mytextptr=textptr(pr_infro),@offest=patindex(‘%D.C%’,pr_infro)-1+4
/*减一是因为有一个矫正的偏移量,加4是因为D.C.是4*/
from  pub_info(unlock)  where  pub_id=’0877’
If  @mytextptr is  not  null  and  @offest=0
   Updatetext  pub_info.pr_infro  @mytextptr  @offest  null  with  log
Commit  tran
例如3:
文本追加的问题
将出版商pub_id=9952的内容追加到出版商Pub_id=0877d的文本中。
Delcare  @source_textptr  varbinary(16),@target_textptr  varbinary(16)
Begin  tran
Select  @source_textptr=textptr(pr_infro)  from  pub_info(uplock)  where  pub_id=’0877’
Select  @target_textptr=textptr(pr_infro)  from  pub_info(uplock)  where  pub_id=’9952’
If  @source_textptr Is not n

来源:https://www.tulaoshi.com/n/20160129/1497928.html

延伸阅读
    mysql数据库表sqltable 字段id,name,sex,email access数据库表accesstable id,name,sex,email ?      $connect = mysql_connect("localhost","","");      mysql_select_db("mydatabase");      $sql = "select * from sqltable;   ...
标签: ASP
save.asp <!-- #include file="adovbs.inc" -- <% ' Constants file included above. ' 如果文件存在则删除 Dim objFSO Set objFSO = Server.CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(Server.MapPath("db_xml.xml")) Then  objFSO.DeleteFile Server.MapPath("db_xml.xml") End IF Set objFSO = Nothing...
笔者认为,在创建索引时要做到三个适当,即在适当的表上、适当的列上创建适当数量的索引。虽然这可以通过一句话来概括优化的索引的基本准则,但是要做到这一点的话,需要数据库管理员做出很大的努力。具体的来说,要做到这个三个适当有如下几个要求。 一、 根据表的大小来创建索引。 虽然给表创建索引,可以提高查询的效率。但是数...
标签: SQLServer
1、打开企业管理器,打开要导入数据的数据库,在表上按右键,所有任务--导入数据,弹出DTS导入/导出向导,按 下一步 , 2、选择数据源 Microsoft Excel 97-2000,文件名 选择要导入的xls文件,按 下一步 , 3、选择目的 用于SQL Server 的Microsoft OLE DB提供程序,服务器...
完整性约束 完整性约束用于增强数据的完整性,Oracle提供了5种完整性约束: Check NOT NULL Unique Primary Foreign key 完整性约束是一种规则,不占用任何数据库空间。完整性约束存在数据字典中,在执行SQL或PL/SQL期间使用。用户可以指明约束是启用的还是禁用的,当约束启用时,他增强了...

经验教程

265

收藏

18
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部