0
當我把這種方法它顯示錯誤:無效的參數,請幫助我得到錯誤:無效的參數時,我從OLEDB數據庫retrive圖像
public void DisplayDoc()
{
try
{
con = new OleDbConnection(constr);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand("Select pic from doc where adharno= '" + this.aadhar + "'", con);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
DataRow row = dt.Rows[0];
pictureEmployeePhoto.Image = LoadPhoto((byte[])row["pic"]);
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error :" + ex.Message);
}
}
private Image LoadPhoto(byte[] photo)
{
MemoryStream ms = new MemoryStream(photo);
return Image.FromStream(ms); //Getting Error Here: Invalid Parameter
}
下面的方法我都用過以將圖像存儲在數據庫中
byte[] Pic;
OpenFileDialog ofdPhoto;
MemoryStream ms = new MemoryStream();
private void btnPhotoUpload_Click(object sender, EventArgs e)
{
// open file dialog
ofdPhoto = new OpenFileDialog();
// image filters
ofdPhoto.Title = "Select Employee Photo";
ofdPhoto.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
ofdPhoto.FileName = null;
if (ofdPhoto.ShowDialog() == DialogResult.OK)
{
// display image in picture box
pictureEmployeePhoto.Image = new Bitmap(ofdPhoto.FileName);
// image file path
txtPhotoFilePath.Text = ofdPhoto.FileName;
try
{
// Here get_image is a function and Big is the byte[] type
Pic = get_image();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message.ToString());
}
}
}
public byte[] get_image()
{
MemoryStream ms = new MemoryStream();
pictureEmployeePhoto.Image.Save(ms,pictureEmployeePhoto.Image.RawFormat);
return ms.GetBuffer();
}
哪一行代碼給你錯誤? –
return Image.FromStream(ms); //錯誤在這裏:無效參數 – ehh
是Chetan Ranpariya –