Image1.Visible = true;
OleDbConnection con = new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data source= " + Server.MapPath(@ "~\App_Data\DataBase.aspx "));
string imagename = " ";
try
{
con.Open();
OleDbCommand com = new OleDbCommand( "select Pic_ID from Picture where Pic_ID= " + DropDownList1.Text + " ", con);
OleDbDataReader dr = com.ExecuteReader();
dr.Read();
MemoryStream ms = new MemoryStream((Byte[])dr[ "Pic_ID "]);
Bitmap image = new Bitmap(ms);
string filepath = Server.MapPath( "Files/ ");
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] filecount = dir.GetFiles();
int i = filecount.Length;
imagename = filepath + ((i + 1) + ".jpg ");
image.Save(imagename);
dr.Close();
Image1.ImageUrl = "Files/ " + ((i + 1) + ".jpg ");
}
catch (Exception error)
{
Label1.Text = "处理失败!原因为: " + error.ToString();
}
finally
{
con.Close();
}
上面代码到 MemoryStream ms = new MemoryStream((Byte[])dr[ "Pic_ID "]);就报错
错误信息是:处理失败!原因为:System.InvalidCastException: Unable to cast object of type 'System.Int32 ' to type 'System.Byte[] '. at 荣誉展示_荣誉展示.Button1_Click(Object sender, EventArgs e) in d:\My Documents\Visual Studio 2005\WebSites\少年宫1\荣誉展示\荣誉展示.aspx.cs:line 44 1 2