web应用程序
已知远程图片地址
以byte[]保存到数据库

解决方案 »

  1.   

    1、用WebClient。DownloadFile下载2、保存/// <summary>
            /// 保存图片内容
            /// </summary>
            /// <param name="strName">图片名称</param>
            /// <param name="strPath">图片路径</param>
            /// <param name="strDescription">图片说明</param>
            /// <param name="strImage">图片内容</param>
            private void SaveTable(string strName, string strPath,string strDescription,byte[] strImage)
            {
                try
                {                using (SqlConnection conn = new SqlConnection("Data Source=192.168.0.21;Initial Catalog=Book Keeping;User ID=sa;Password=sa;Connection Timeout=60;"))
                    {
                        conn.Open();
                        SqlCommand comm = new SqlCommand();
                        string strSql = "Insert into PictureInfo(strName,strPath,strDescription,strImageContent) values (@Name,@Path,@Description,@Image)";
                        comm.CommandText = strSql;
                        comm.CommandType = CommandType.Text;
                        comm.Connection = conn;
                        comm.Parameters.Add("@Name",SqlDbType.VarChar);
                        comm.Parameters.Add("@Path",SqlDbType.VarChar);
                        comm.Parameters.Add("@Description",SqlDbType.VarChar);
                        comm.Parameters.Add("@Image",SqlDbType.Image);                    comm.Parameters[0].Value = strName;
                        comm.Parameters[1].Value = strPath;
                        comm.Parameters[2].Value = strDescription;
                        comm.Parameters[3].Value = strImage;                    comm.ExecuteNonQuery();
                    }
                }
                catch(Exception)
                {
                }
            }
      

  2.   

    关键这一段 “用WebClient。DownloadFile下载”不会写,保存的会写。
      

  3.   

    怎么从这“用WebClient。DownloadFile下载”得到byte[]的数据。
      

  4.   

    汗~WebClient直接可以得到byte[],才看到,谢谢指点方向。