none
I save the image data by converting it into byte array from base64 and image data is also inserted into database, now how to retrieve it back in base64 string. ? RRS feed

  • Question

  • What I did Yet :- 

    [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));
                }
            }

                               Now i am Getting Error on :-      business.BusinessLogo = Convert.ToBase64String(rdr["BusinessLogo"]);        
    Wednesday, July 4, 2018 8:53 AM

All replies

  • Hello,

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


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, July 4, 2018 9:06 AM
    Moderator
  • i completed my first question 

    now please give me the solution of this question  ?
    • Edited by AnkitSoni29 Wednesday, July 4, 2018 9:25 AM
    Wednesday, July 4, 2018 9:25 AM
  • Hi AnkitSoni29,

    Please convert it to Byte[] first, then convert it to Base64String like this:

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


    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 5, 2018 5:19 AM
    Moderator