Dorababu Meka

Dorababu Meka

  • 226
  • 8.3k
  • 1.7m

Blob In SQL

May 28 2009 2:39 AM
Hi i use the following code to get the image from  SQL database


  string sConn = @"Data Source=SYSTEM1;Initial Catalog=BLOBTest4;Integrated Security=True";
        SqlConnection objConn = new SqlConnection(sConn);
        objConn.Open();

        string sTSQL = "SELECT TheName FROM FileInfo";

        SqlCommand objCmd = new SqlCommand(sTSQL, objConn);
        objCmd.CommandType = CommandType.Text;

        SqlDataReader dr = objCmd.ExecuteReader();
        dr.Read();

        Response.BinaryWrite((byte[])dr["TheName"]);

        objConn.Close();

My SQL table is as follows
column name : The Name Datatype : varchar
column name : Dirpath Datatype : varchar


I am geeting the following error can  any one rectify this error

Unable to cast object of type 'System.String' to type 'System.Byte[]'.


Answers (8)