将图像存储在mssql server vb.net中

时间:2015-01-13 14:00:19

标签: image sql-server-2008

嗨我在将图像存储到mssql服务器时遇到问题我同时尝试了内存流和BLOB以及两个scinarios我都得到了相同的错误“无法将值null插入图像列msg 515 16级状态2行1” ,任何建议都非常欢迎谢谢。

             Dim sqlstring = " begin tran;"
             sqlstring &= " INSERT INTO tbl_customers (stnname, cardnum,
             family_name,  city, fam_mem_nu, id_num, mrkz_num) VALUES
             ('" & stn & "','" & cd & "', '" & fmnm & "','" & ct & "', '" 
             & fnum & "', '" & idn & "', '" & cntr & "')"
             sqlstring &= "INSERT INTO tbl_customers(imag) SELECT * FROM  
             OPENROWSET(BULK N'c:\temp\tempimg', SINGLE_BLOB) imag ;  "
             sqlstring &= "commit tran;"
             sql.CommandText = sqlstring
             sql.Connection = conn
             conn.Open()
             Dim ms As New MemoryStream

             img = CameraControl1.SnapshotSourceImage   


             img.Save("c:\temp\tempimg", Imaging.ImageFormat.Png)

            'CameraControl1.SnapshotSourceImage.Save(ms, Imaging.ImageFormat.Bmp)
            ' PictureBox3.Image.Save(ms, PictureBox3.Image.RawFormat)
             ' ms.ToArray()
            ' Dim data As Byte() = ms.GetBuffer()
            '  Dim p As New SqlClient.SqlParameter("@img", SqlDbType.VarBinary)
            ' p.Value = data
            ' sql.Parameters.Add(p)
            Dim x As Integer = sql.ExecuteNonQuery

0 个答案:

没有答案