陈斌彬的技术博客

Stay foolish,stay hungry

Webservice 读取 SQL 图片二进制数据

[WebMethod]
      public byte[] GetImageInfo()
      {
          string cnnstr = "Data Source=JOHN;Initial Catalog=webservice;User ID=sa;Password=12345678";
          string sql = "select * from  imagetable";

          SqlConnection conn = new SqlConnection(cnnstr);
          conn.Open();

          SqlCommand comm = new SqlCommand();
          comm.Connection = conn;
          comm.CommandType = CommandType.Text;
          comm.CommandText = sql;
          SqlDataReader dr = comm.ExecuteReader();

          byte[] bytes=null;

          while(dr.Read()){

          bytes = (byte[])dr["imageLabel"];
          }
          return bytes;
      }