本文介绍了我通过将图像数据从base64转换为字节数组来保存图像数据,图像数据也插入到数据库中,现在如何在base64字符串中检索它。 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的所作所为: -  

[WebMethod]

        public void GetBusiness(Int64 ID)

        {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;列表与LT;商务> listEmployees = new List< Business>();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;试试
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; using(SqlConnection connection = new SqlConnection(GetConnectionString())))
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SqlCommand sqlcom = new SqlCommand(" [GetBusiness]",connection);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; sqlcom.CommandType = CommandType.StoredProcedure;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; sqlcom.Parameters.AddWithValue(" @ ID",ID);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; connection.Open();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; SqlDataReader rdr = sqlcom.ExecuteReader();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; while(rdr.Read())

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;商业业务=新业务();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.ID = Convert.ToInt64(rdr [" ID"]);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.BusinessName = rdr [" BusinessName"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.FirstName = rdr [" FirstName"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.LastName = rdr [" LastName"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.Address = rdr [" Address"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.City = rdr [" City"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.State = rdr [" State"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.Country = rdr [" Country"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.EmailID = rdr [" EmailID"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.ContactNumber = rdr [" ContactNumber"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.AppDownloaded = rdr [" AppDownloaded"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.AppUpgrade = rdr [" AppUpgrade"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.AppVersion = rdr [" AppVersion"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.CreatedDate = rdr [" CreatedDate"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.RowStatus = Convert.ToInt16(rdr [" RowStatus"]);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.UserName = rdr [" UserName"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.AdminPassword = rdr [" AdminPassword"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.IPAddress = rdr [" IPAddress"]。ToString();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; business.BusinessLogo = Convert.ToBase64String(rdr [" BusinessLogo"]); 



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; listEmployees.Add(business);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JavaScriptSerializer js = new JavaScriptSerializer();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Context.Response.Write(js.Serialize(listEmployees));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; catch(例外情况)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; JavaScriptSerializer a =新的JavaScriptSerializer();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var varResult = new {result =" Error",Error = ex};

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Context.Response.Write(a.Serialize(varResult));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; }

[WebMethod]
        public void GetBusiness(Int64 ID)
        {
            List<Business> listEmployees = new List<Business>();
            try
            {


                using (SqlConnection connection = new SqlConnection(GetConnectionString()))
                {
                    SqlCommand sqlcom = new SqlCommand("[GetBusiness]", connection);
                    sqlcom.CommandType = CommandType.StoredProcedure;
                    sqlcom.Parameters.AddWithValue("@ID", ID);
                    connection.Open();
                    SqlDataReader rdr = sqlcom.ExecuteReader();
                    while (rdr.Read())
                    {
                        Business business = new Business();
                        business.ID = Convert.ToInt64(rdr["ID"]);
                        business.BusinessName = rdr["BusinessName"].ToString();
                        business.FirstName = rdr["FirstName"].ToString();
                        business.LastName = rdr["LastName"].ToString();
                        business.Address = rdr["Address"].ToString();
                        business.City = rdr["City"].ToString();
                        business.State = rdr["State"].ToString();
                        business.Country = rdr["Country"].ToString();
                        business.EmailID = rdr["EmailID"].ToString();
                        business.ContactNumber = rdr["ContactNumber"].ToString();
                        business.AppDownloaded = rdr["AppDownloaded"].ToString();
                        business.AppUpgrade = rdr["AppUpgrade"].ToString();
                        business.AppVersion = rdr["AppVersion"].ToString();
                        business.CreatedDate = rdr["CreatedDate"].ToString();
                        business.RowStatus = Convert.ToInt16(rdr["RowStatus"]);
                        business.UserName = rdr["UserName"].ToString();
                        business.AdminPassword = rdr["AdminPassword"].ToString();
                        business.IPAddress = rdr["IPAddress"].ToString();
                        business.BusinessLogo = Convert.ToBase64String(rdr["BusinessLogo"]); 

                        listEmployees.Add(business);
                    }
                }
                JavaScriptSerializer js = new JavaScriptSerializer();
                Context.Response.Write(js.Serialize(listEmployees));
            }
            catch (Exception ex)
            {
                JavaScriptSerializer a = new JavaScriptSerializer();
                var varResult = new { result = "Error", Error = ex };
                Context.Response.Write(a.Serialize(varResult));
            }
        }

推荐答案

请以
第一个问题
然后再问自己这个问题。

Please finish up with your first question before concerning yourself with this question.


这篇关于我通过将图像数据从base64转换为字节数组来保存图像数据,图像数据也插入到数据库中,现在如何在base64字符串中检索它。 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:40