Ejemplo n.º 1
0
        /// <summary>
        /// Return stream private extenstions, just for testing..
        /// </summary>
        /// <param name="streamID"></param>
        /// <returns></returns>
        public static Hashtable GetStreamPrivateExtensions(int streamID)
        {
            String query = "select privextns from stream where stream_id=" + streamID;

            if (!DatabaseUtility.openAndExecute(query))
            {
                return(null);
            }

            try
            {
                if (reader.Read())
                {
                    System.Data.SqlTypes.SqlBinary sb = reader.GetSqlBinary(0);
                    byte[]    ba = sb.Value;
                    object    o  = Utility.ByteArrayToObject(ba);
                    Hashtable h  = (Hashtable)o;
                    return(h);
                }
            }
            finally
            {
                DatabaseUtility.cleanUpConnection();
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// 带参数的sql语句,单参数
        /// <param name="sqltext">sql语句</param>
        /// <returns>返回大字段参数</returns>
        public static System.Data.SqlTypes.SqlBinary ExecuteBinarysqlToBinary(string sqltext, string connstr)
        {
            System.Data.SqlTypes.SqlBinary sb = new System.Data.SqlTypes.SqlBinary();

            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connstr);

            try
            {
                System.Data.SqlClient.SqlCommand scomm = new SqlCommand(sqltext, conn);

                conn.Open();

                System.Data.SqlClient.SqlDataReader sr = scomm.ExecuteReader();

                if (sr != null && sr.HasRows)
                {
                    sr.Read();
                    sb = sr.GetSqlBinary(0);
                }

                sr.Close();
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw (ex);
            }
            finally
            {
                if (conn.State.ToString() != "Closed")
                {
                    conn.Close();
                }
            }
            return(sb);
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            Response.ContentType = "image/jpeg";
            int width  = 110;
            int height = 140;

            if (Request.QueryString.Count >= 3)
            {
                width  = int.Parse(Request.QueryString["w"]);
                height = int.Parse(Request.QueryString["h"]);
            }
            string s = " SELECT * FROM dbo.tbl_Core_PeopleImages ";

            s += " WHERE (PersonId = '" + Request.QueryString["id"] + "' ) ";
            s += " ORDER BY ImageDate DESC";
            Encode en            = new Encode();
            string db_connection = en.GetDbConnection();

            using (SqlConnection cn = new SqlConnection(db_connection))
            {
                cn.Open();
                using (SqlCommand cm = new SqlCommand(s, cn))
                {
                    using (SqlDataReader dr = cm.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            System.Data.SqlTypes.SqlBinary b1 = new System.Data.SqlTypes.SqlBinary();
                            b1 = dr.GetSqlBinary(2);
                            byte[] b3 = new byte[b1.Length];
                            b3 = (byte[])b1;
                            MemoryStream ms1     = new MemoryStream(b3);
                            Bitmap       myImage = new Bitmap(ms1);
                            myImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        else
                        {
                            Bitmap   b = new System.Drawing.Bitmap(width, height);
                            Graphics g = Graphics.FromImage(b);
                            g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), 0, 0, width, height);
                            b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        dr.Close();
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void Insert()
 {
     using (SqlConnection Connection = new SqlConnection(Properties.Settings.Default.SkyDatabaseConnectionString))
     {
         var binaryContent = new System.Data.SqlTypes.SqlBinary(Content);
         Connection.Open();
         SqlCommand command = new SqlCommand()
         {
             Connection = Connection
         };
         command.CommandText = "INSERT INTO [Message] VALUES(@user_id, @chat_id, @ContentType, @content, @date)";
         command.Parameters.Add(new SqlParameter("@user_id", User_id));
         command.Parameters.Add(new SqlParameter("@chat_id", Chat_id));
         command.Parameters.Add(new SqlParameter("@ContentType", ContentType));
         command.Parameters.Add(new SqlParameter("@content", binaryContent));
         command.Parameters.Add(new SqlParameter("@date", Date));
         command.ExecuteNonQuery();
     }
 }