我有一个用户表:
Name varchar(20)
Picture image
Run Code Online (Sandbox Code Playgroud)
我想将图像存储到Picture列中 - 如何使用SQL Scripts实现此目的?
Can*_*var 10
这是一个用于将图像存储到sql server的示例代码:
SqlConnection conn = new SqlConnection(connectionString);
try
{
int imageLength = uploadInput.PostedFile.ContentLength;
byte[] picbyte = new byte[imageLength];
uploadInput.PostedFile.InputStream.Read (picbyte, 0, imageLength);
SqlCommand command = new SqlCommand("INSERT INTO ImageTable (ImageFile) VALUES (@Image)", conn);
command.Parameters.Add("@Image", SqlDbType.Image);
command.Parameters[0].Value = picbyte;
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
注意: uploadInput是一个文件输入控件,用于将图像文件上传到服务器.从ASP.NET应用程序获取的代码.
编辑:这是图像类型列的插入脚本:
INSERT INTO ImageTable (ImageColumn)
SELECT ImageColumn FROM
OPENROWSET(BULK N'C:\SampleImage.jpg', SINGLE_BLOB)
AS ImageSource(ImageColumn);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4654 次 |
| 最近记录: |