将图像插入数据库 [英] inserting image into database
本文介绍了将图像插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
由于我是vb.net的新手,能否给我一个有关如何将图像插入
的建议
sql database
Hi Friends,
As i am new to vb.net.Can you give me a suggestion for how to insert image into
sql database
推荐答案
1)调出SQL Server Management Studio.
2)连接,然后打开要将图像添加到的数据库.
3)展开表,然后添加带有适当索引字段的新表,或者右键单击该表并选择设计.
4)添加一个名为"myImage"的字段,并将其数据类型设置为"image".允许为空.
5)关闭SQL Server Management Studio.
要将图像添加到表中(我将假设一个新记录,该表具有一个Identity字段,而只有myImage列):
1) Bring up SQL Server Management Studio.
2) Connect, and open the database you want to add the image to.
3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design.
4) Add a field called "myImage", and make its datatype "image". Allow nulls.
5) Close SQL Server Management studio.
To add images to the table (I will assume a new record, the table has an Identity field, and just the myImage column):
Using con As New SqlConnection(connectionString)
Using com As New SqlCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con)
Dim imageData As Byte() = File.ReadAllBytes("D:\Temp\Picture.jpg")
com.Parameters.AddWithValue("@IM", imageData)
com.ExecuteNonQuery()
End Using
End Using
这篇关于将图像插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文