您的位置:程序门 -> .net技术 -> vb.net



将图片保存在oracle数据库中去,求大家帮个忙


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


将图片保存在oracle数据库中去,求大家帮个忙
发表于:2007-01-03 15:28:36 楼主
oracle数据库结构
字段名         类型
  aa               blob


我先将图片转换成文件流

再把这个文件流转成二进制数组到 mybyte()中去

strsql= "insert   into   表1 values   (mybtye) "

在程序里写这个sql语句报错,无法执行

请问大家如何将这个二进制数组存到数据库中去

发表于:2007-02-02 20:25:401楼 得分:0
private   sub   binddata()
                try
                        dim   sql   as   string   =   "select   编号,   姓名,   身份证号,   性别,   任职部门,   直属主管,   目前岗位,   家庭住址,   联系地址,   邮政编码,   电话号码,   婚姻状况,   出生日期, "   &   _
                "   进校日期,   离校日期,   备注说明,   照片   from   employee "
                        dim   dt   as   datatable   =   getdatatable(sql)
                        if   dt.rows.count   <>   0   then
                                me.datagrid1.datasource   =   dt
                                me.bindtextbox(0)
                                cm   =   me.bindingcontext(dt)
                                me.lbl记录数.text   =   string.format( "当前第{0}条,共{1}条记录! ",   cm.position   +   1,   cm.count)
                        end   if
                catch   ex   as   exception
                        writeerr(ex)
                end   try
        end   sub
'添加图片过程
private   sub   insertdata()
                dim   photoname   as   string   =   me.openfiledialog1.filename.trim()
                dim   mystream   as   new   filestream(photoname,   filemode.open,   fileaccess.read)             '根据图片路径将图片转换为文件流
                dim   buffer(mystream.length)   as   byte                               '实例化一个字节数组
                mystream.read(buffer,   0,   mystream.length)                   '将文件流读入二进制字节数组
                mystream.close()                                                                     '关闭文件流
                dim   sql   as   string   =   "insert   into   employee(编号,   姓名,   身份证号,   性别,   任职部门,   直属主管,   目前岗位,   家庭住址,   联系地址,   邮政编码,   电话号 "   &   _
                                "码,   婚姻状况,   出生日期,   进校日期,   离校日期,   备注说明,   照片)   values   ( ' "   +   me.txt编号.text.trim()   +   " ',   ' "   +   me.txt姓名.text.trim()   +   " ',   ' "   +   me.txt身份证号.text.trim()   +   " ',   ' "   +   me.cmb性别.text.trim()   +   " ',   ' "   +   me.cmb任职部门.text.trim()   +   " ',   ' "   +   me.txt直属主管.text.trim()   +   " ', "   &   _
                                " ' "   +   me.cmb目前岗位.text.trim()   +   " ',   ' "   +   me.txt家庭住址.text.trim()   +   " ', ' "   +   me.txt联系地址.text.trim()   +   " ', ' "   +   me.txt邮政编码.text.trim()   +   " ',   ' "   +   me.txt电话号码.text.trim()   +   " ',   ' "   +   me.cmb婚姻状况.text.trim()   +   " ',   ' "   +   me.txt出生日期.text.trim()   +   " ', ' "   +   me.txt进校日期.text.trim()   +   " ',   ' "   +   me.txt离校日期.text.trim()   +   " ',   ' "   +   me.txt备注说明.text.trim()   +   " ',   @image) "
                dim   cmd   as   new   sqlcommand
                cmd.parameters.add( "@image ",   buffer)
                cmd.connection   =   con
                cmd.commandtext   =   sql

                try
                        con.open()
                        cmd.EXECutenonquery()
                        messagebox.show( "添加记录成功! ",   "系统提示 ",   messageboxbuttons.ok,  
messageboxicon.information)
                catch   ex   as   exception
                        messagebox.show( "添加记录失败! ",   "系统提示 ",   messageboxbuttons.ok,   messageboxicon.information)
                        writeerr(ex)
                finally
                        con.close()
                end   try
                binddata()
        end   sub

'获得表
  public   function   getdatatable(byval   sql   as   string)   as   datatable
                dim   dt   as   new   datatable

                try
                        con.open()
                        dim   sqlada   as   new   sqldataadapter(new   sqlcommand(sql,   con))
                        sqlada.fill(dt)
                        con.close()
                catch   ex   as   exception
                        writeerr(ex)
                        'messagebox.show(ex.message)
                end   try

                return   dt
        end   function

        '写错误日志
        public   sub   writeerr(byval   ex   as   exception)

                dim   path   as   string   =   application.startuppath   +   "\err01.txt "
                if   not   file.exists(path)   then
                        file.create(path)
                end   if
                dim   sw   as   streamwriter   =   file.appendtext(path)
                sw.write(system.datetime.now.tostring()   +   vbcrlf)
                sw.write(ex.message   +   vbcrlf)
                sw.write(ex.stacktrace   +   vbcrlf)
                sw.flush()
                sw.close()

        end   sub
发表于:2007-02-21 16:20:312楼 得分:0
该回复于2007-12-21 19:42:52被管理员或版主删除


快速检索

最新资讯
热门点击