GamingAttic
New Member
Hi all,<BR>I have a database table to store photos with PhotoID field as auto number and PhotoFile field as binary data (not allow null) to hold real image. In my ASP.NET page I need to retrieve these photos to do some processing. So I have some C# codes embedded in my ASP+ page like this:<BR>String ConnStr = "server=(local);uid=sa;pwd=;database=MyDB";<BR>SqlConnection Con = new SqlConnection(ConnStr);<BR>String SqlCmd = "SELECT PhotoID, PhotoFile FROM Photos1";<BR>//String SqlCmd = "SELECT PhotoID, PhotoFile FROM Photos1 where PhotoID in (1,2)";<BR>SqlCommand SqlCmdObj = new SqlCommand( SqlCmd, Con );<BR>Con.Open();<BR>//SqlDataReader SqlReader = SqlCmdObj.ExecuteReader(CommandBehavior.CloseConne ction);<BR>SqlDataReader SqlReader = SqlCmdObj.ExecuteReader();<BR>while (SqlReader.Read()) {<BR>int PhotoID = (int)SqlReader["PhotoID"];<BR>System.Drawing.Image _image = System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])SqlReader["PhotoFile"]));<BR>...<BR>...<BR>}<BR><BR>one strange problem is, if only one record returned, that is loop for only one time, everything works fine as what I need. BUT if multiple records returned, that is to loop more than one time, I will get a compilation error: "Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Invalid parameter used." on the last statement I wrote.<BR>So I just wonder if there are some tricks to load BLOB data in .NET from a loop? or it even cannot be loaded twice at a time?<BR>anybody has some suggestion? thanks!