none
cannot implicitly convert type string to int RRS feed

  • Question

  • Hi,

    Can anybody point to me what's wrong in my code error should thrown in my
    code cannot implecitly convert string to int

    how can i solve this error

    My code:
    HttpContext context;
    DataSet ds = new DataSet();
    objBLLogin = new BLProject();
    ds = objBLLogin.LoadImage();
    foreach (DataRow[] tempRow in ds.Tables[0].Rows)
    {
    context.Response.BinaryWrite((byte[])tempRow["ImageData"]);
    }


    this line: context.Response.BinaryWrite((byte[])tempRow["ImageData"]);
    getting the error.

    thanks and regards
    kumar


    Thursday, February 4, 2010 7:01 AM

All replies

  • Hi Britekumar,

    Thank you for your post.

    It seems that data type can not be converted correctly when you do ((byte[])tempRow["ImageData"]), please check the data type of the value in field ImageData.

    How did you load the image to the dataset and how the image is stored, could you provide more information and sample codes?  Thank you.

    Best regards,
    Alex Liang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, February 5, 2010 9:53 AM
    Moderator
  • You could do something like this:

    public byte[] SerializeDataRow(System.Data.DataRow row)
            {
                if(row == default(System.Data.DataRow))
                    return default(byte[]);
    
                System.IO.MemoryStream memStream = new System.IO.MemoryStream();
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(object[]));
                serializer.Serialize(memStream, row.ItemArray);
    
                return memStream.ToArray();
            }
    Then to deserialize:

    public void DeserializeDataRow(System.Data.DataTable table, byte[] rowBytes)
            {
                if (table == default(System.Data.DataTable) || rowBytes == default(byte[]))
                    return;
    
                System.IO.MemoryStream memStream = new System.IO.MemoryStream(rowBytes);
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(object[]));
                table.Rows.Add((object[])serializer.Deserialize(memStream));
            }


    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, February 5, 2010 7:04 PM