.NET 连接SQL SERVER2000数据库时如何操作IMAGE字段?
问题1:我的数据库中有一个字段为image 字段
我想在.net 中把该字段的数据显示到datagrid中或显示到picture控件中,
问题2:如果我在窗口中更改了一个图片该如何上传到数据库中?
哪位有关于.net 连接 sql server 读取,存放图片的例子.谢谢
推荐阅读
读取到picturebox
dim pic() as byte=ctype(mydataset.tables(0).rows(0)("pic"),byte)
dim ms as new memorystream(pic)
picturebox1.image=image.fromstream(ms)
string id = (string) context.request["id"];
if (id != null) {
memorystream stream = new memorystream ();
sqlconnection connection = new sqlconnection
("server=localhost;database=northwind;uid=sa;pwd=");
bitmap bitmap = null;
image image = null;
try {
connection.open ();
sqlcommand cmd = new sqlcommand
("select photo from employees where employeeid=" +
id + "", connection);
byte[] blob = (byte[]) cmd.executescalar ();
stream.write (blob, 78, blob.length - 78);
bitmap = new bitmap (stream);
// shrink the image, but maintain its aspect ratio
int width = 48;
int height = (int) (width *
((double) bitmap.height / (double) bitmap.width));
image = bitmap.getthumbnailimage (width, height, null,
intptr.zero);
context.response.contenttype = "image/jpeg";
image.save (context.response.outputstream, imageformat.jpeg);
}
finally {
if (image != null)
image.dispose ();
if (bitmap != null)
bitmap.dispose ();
stream.close ();
connection.close ();
}


讨论区