📄 getdata.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
namespace photo
{
public class image_query
{
string image_filename = null;
byte[] image_bytes = null;
SqlConnection image_connection = null;
SqlCommand image_command = null;
SqlDataReader image_reader = null;
public image_query()
{
image_connection = new SqlConnection(
@"Data Source=(local);" +
"Integrated Security=SSPI;" +
"Initial Catalog=EAlbum;" +
"Connect Timeout=3");
image_command = new SqlCommand(
@"SELECT name, photo FROM Photos",
image_connection);
// Open the connection and read data into the DataReader.
image_connection.Open();
image_reader = image_command.ExecuteReader();
}
public Bitmap get_image()
{
MemoryStream ms = new MemoryStream(image_bytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
public string get_filename()
{
return image_filename;
}
public bool get_row()
{
//如果还可以读取 则读取该行
if (image_reader.Read())
{
image_filename = (string) image_reader.GetValue(0);
image_bytes = (byte[]) image_reader.GetValue(1);
return true;
}
else
{
return false;
}
}
public void end_query()
{
// Close the reader and the connection.
image_reader.Close();
image_connection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -