I work on window C# vs05. i want to read a image by IDataReader....in oledb....how can i do it suppose i want to read int value from database column name student id then i write code in bellow way
private IDataReader _reader;
public int GetInt32(String sFieldName)
{
return (_reader[sFieldName]==DBNull.Value)? (Int32) 0 :Convert.ToInt32(_reader[sFieldName]);
}
To save the image i use bellow code
DataTable oTable = new DataTable();
oTable.Columns.Add("BoardImage");
DataRow oRow = oTable.NewRow();
oRow["BoardImage"] = oItem.BoardImage;
SQL= Insert into table oRow["BoardImage"];
Now i want to read image BY Idatareader ......to do that i write bellow code but i get error message "Parameter is not valid."
public Image GetImage(String sFieldName)
{
try
{
//MemoryStream stream = new MemoryStream();
//stream.Write(image, 0, image.Length);
//Bitmap bitmap = new Bitmap(stream);
byte[] imageData = null;
long byteSize = 0;
byteSize = _reader.GetBytes(_reader.GetOrdinal(sFieldName), 0, null, 0, 0); **//May be error occur here**
imageData = new byte[byteSize];
long bytesread = 0;
int curpos = 0, chunkSize = 500;
while (bytesread < byteSize)
{
// chunkSize is an arbitrary application defined value
bytesread += _reader.GetBytes(_reader.GetOrdinal(sFieldName), curpos, imageData, curpos, chunkSize);
curpos += chunkSize;
}
byte[] imgData = imageData;
MemoryStream ms = new MemoryStream(imgData); **//May be error occur here**
Image oImage = Image.FromStream((Stream)ms);
return oImage;
}
catch(Exception ex)
{
throw new Exception("Failed to get Image: " + ex.Message);
}
}
can any one help me ?Where is my bug.....How to solve this problem
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…