如何使用vb.net2008将Image插入数据库sqlserver 2005 [英] How to insert Image to database sqlserver 2005 using vb.net2008
本文介绍了如何使用vb.net2008将Image插入数据库sqlserver 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我的问题是如何使用vb.net 2008将图像插入到sqlserver 2005,我的表名是Image_tbl,而在image_ID字段中的字段是(Image_ID和照片)我存储图片的名称和我想要的照片字段商店形象。所以我的代码工作,但只有图像名称是sstoring但照片不是,并在照片字段显示'二进制数据'的文本...所以我需要你的帮助,需要简单的代码为此。我的代码是:
hello my question is how to insert image to sqlserver 2005 using vb.net 2008 , my Table name is Image_tbl, and Fields are (Image_ID and Photos) in image_ID field i am storing name of picture and In Photos Field i want to store image. So my code is working but only image name is sstoring but photos are not and in the photos field showing text of 'binary data'... so i need your help ,need simple code for this.And my code Is:
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Form1
Dim cn As New SqlConnection("Data Source=NIDA-PC\SQLEXPRESS;Initial Catalog=Finaldb;Integrated Security=True")
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim ms As New MemoryStream
Dim cmd As New SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Dim n As Integer
Dim Photo_aray As Byte
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
cn.Open()
cmd.CommandText = "Insert into Image_tbl(Image_ID,Photos)Values('" & TextBox1.Text & "','" & OpenFileDialog1.FileName & "')"
cmd.Connection = cn
Int(n = cmd.ExecuteNonQuery())
MsgBox("insert Image successfully")
cn.Close()
End Sub
End Class
推荐答案
参考:保存并从中检索图像使用VB.NET的SQL Server数据库 [ ^ ]
我也使用此代码,但这不能正常工作...
me also using this code but this is not working properly ...
这篇关于如何使用vb.net2008将Image插入数据库sqlserver 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文