以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  sql插入二进制照片  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=124553)

--  作者:susu312
--  发布时间:2018/9/8 23:54:00
--  sql插入二进制照片

cmd.CommandText = "插入 person (cardID, age, birth,tel,jiguan,rational,edu,health,workdate,name,politicalStatus,hobbies,"& _
                                        "retiredPost,title,address,leaOrRetire,retireTime,proTecPost,proSpecialty,partyBranch,"& _
                                        "partyTime,presonalClass,organName,partyStanding,retiredDep,guanZhu,jianli,sex,fuZhu)"& _
                                        "Values(?,?,?,?,?,  ?,?,?,?,?,  ?,?,?,?,?,  ?,?,?,?,?,  ?,?,?,?,? ,?,?,?,?);Select SCOPE_IDENTITY()"
cmd.Parameters.Add("@cardID",cardID)
cmd.Parameters.Add("@age",age)
cmd.Parameters.Add("@birth",birth)
cmd.Parameters.Add("@tel",tel)
cmd.Parameters.Add("@jiguan",jiguan)
cmd.Parameters.Add("@rational",rational)
cmd.Parameters.Add("@edu",edu)
cmd.Parameters.Add("@health",health)
cmd.Parameters.Add("@workdate",workdate)
cmd.Parameters.Add("@name",name)

cmd.Parameters.Add("@politicalStatus",politicalStatus)
cmd.Parameters.Add("@hobbies",hobbies)
cmd.Parameters.Add("@retiredPost",retiredPost)
cmd.Parameters.Add("@title",title)
cmd.Parameters.Add("@address",address)
cmd.Parameters.Add("@leaOrRetire",leaOrRetire)
cmd.Parameters.Add("@retireTime",retireTime)
cmd.Parameters.Add("@proTecPost",proTecPost)
cmd.Parameters.Add("@proSpecialty",proSpecialty)
cmd.Parameters.Add("@partyBranch",partyBranch)

cmd.Parameters.Add("@partyTime",partyTime)
cmd.Parameters.Add("@presonalClass",presonalClass)
cmd.Parameters.Add("@organName",organName)
cmd.Parameters.Add("@partyStanding",partyStanding)
cmd.Parameters.Add("@retiredDep",retiredDep)
cmd.Parameters.Add("@guanZhu",guanZhu)
cmd.Parameters.Add("@jianli",jianli)
cmd.Parameters.Add("@sex",sex)
cmd.Parameters.Add("@fuZhu",fuZhu)
\'cmd.Parameters.Add("@photo", "0x" + ImageString + "" )
cmd.ExecuteNonQuery
Dim id As Integer = cmd.ExecuteScalar()
MessageBox.Show(id)
cmd.CommandText = "更新 person set photo = 0x" + ImageString + " where _Identify =  "& id-1 
\'cmd.ExecuteNonQuery()

 

 

通过这个方式插入的照片,比如新的id是19,但是获得的id总是20?为啥?


--  作者:有点甜
--  发布时间:2018/9/9 15:54:00
--  

你执行了两次

 

cmd.ExecuteNonQuery
Dim id As Integer = cmd.ExecuteScalar()