D
deko
What I want to do is call the static method in the below class.
In pseudo code it might look something like this:
If (!GetImageFromDatabase.ExtractImage(strFileName,
strPathToImageFile))
{
// do something
}
In other words, if the method returns false, execute some code.
How do I set the return type for this method?
How do I call it from another class?
Thanks in advance.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace ImageSwitcher
{
class GetImageFromDatabase
{
public static bool ExtractImage(string strFileName,
string strPathToImageFile)
{
OleDbConnection cnxOle = new OleDbConnection();
OleDbCommand cmdOle = new OleDbCommand();
MemoryStream ms = new MemoryStream();
Try
//basically, I want to turn error handling off
//is this how to do it?
{
cnxOle.ConnectionString =
("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
+ Application.StartupPath + @"\SomeImages.mdb");
string strSql = "SELECT Photo FROM Photos WHERE FileName = "
+ '\u0022' +
strFileName + '\u0022';
cmdOle = new OleDbCommand(strSql, cnxOle);
int offset = 78;
cnxOle.Open();
byte[] img = (byte[])cmdOle.ExecuteScalar();
ms.Write(img, offset, img.Length - offset);
Bitmap bmp = null;
bmp = new Bitmap(ms);
bmp.Save(strPathToImageFile, ImageFormat.Bmp);;
}
finally
{
ms.Close();
cnxOle.Close();
//=====PROBLEM================================================
//Error: Cannot assign to 'ExtractImage' because it is a
'method group'
//=============================================================
ExtractImage = File.Exists(strPathToImageFile);
// so if there's no file, something went wrong
}
} //end method ExtractImage
} //end class GetImageFromDatabase
} //end namespace ImageSwitcher
In pseudo code it might look something like this:
If (!GetImageFromDatabase.ExtractImage(strFileName,
strPathToImageFile))
{
// do something
}
In other words, if the method returns false, execute some code.
How do I set the return type for this method?
How do I call it from another class?
Thanks in advance.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace ImageSwitcher
{
class GetImageFromDatabase
{
public static bool ExtractImage(string strFileName,
string strPathToImageFile)
{
OleDbConnection cnxOle = new OleDbConnection();
OleDbCommand cmdOle = new OleDbCommand();
MemoryStream ms = new MemoryStream();
Try
//basically, I want to turn error handling off
//is this how to do it?
{
cnxOle.ConnectionString =
("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
+ Application.StartupPath + @"\SomeImages.mdb");
string strSql = "SELECT Photo FROM Photos WHERE FileName = "
+ '\u0022' +
strFileName + '\u0022';
cmdOle = new OleDbCommand(strSql, cnxOle);
int offset = 78;
cnxOle.Open();
byte[] img = (byte[])cmdOle.ExecuteScalar();
ms.Write(img, offset, img.Length - offset);
Bitmap bmp = null;
bmp = new Bitmap(ms);
bmp.Save(strPathToImageFile, ImageFormat.Bmp);;
}
finally
{
ms.Close();
cnxOle.Close();
//=====PROBLEM================================================
//Error: Cannot assign to 'ExtractImage' because it is a
'method group'
//=============================================================
ExtractImage = File.Exists(strPathToImageFile);
// so if there's no file, something went wrong
}
} //end method ExtractImage
} //end class GetImageFromDatabase
} //end namespace ImageSwitcher