getdata.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- 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();
- }
- }
- }