By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

Convert VB to C# for saving/reading an image from Access DB

P: n/a
Hi,

I am trying to save and read an image from MS Access DB based on the
following article:

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

Right now, I saved images without any errors. After reading the ole object
from db, I saved it to C: as file1.bmp and displayed on the web. But it can
not be displayed. After I manually sent the file to wordpad, it shows

System.Byte [ ]

Now I suspect my saving an image might be wrong. The table has 2 columns:
username and userfile. Userfile column shows

..ong binary data

I can not find a way to verify if data was saved ok? But saving does not
report any errors. I am attached my saving and reading codes here to see if
anyone can help?

THanks. –dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
if (dListUsers.SelectedValue == "")
{
lblFileAccess.Text = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFile.FileName;
// only the attched file name not its path
string c = System.IO.Path.GetFileName(curFileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
+ ("VALUES ("
+ (dbClass.DelimString(dListUsers.SelectedValue) + (","
+ ("\'"+rawData + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sSQL, dbConn);
dbCmd.ExecuteNonQuery();
dbConn.Close();
lblFileAccess.Text = "The file has been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
lblFileAccess.Text = "The file has not been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
}

private void btnReadFmDB_Click(object sender, System.EventArgs e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.SelectedValue + "\'";
FileStream fs;
BinaryWriter bw;
int bufferSize = 300000;
//byte[] outbyte;
byte[] outbyte = new byte[300000 - 1];

long retval;
//long startIndex = 0;
//string pub_id = "";

try
{
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sql, dbConn);
dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
while (dbDR.Read())
{
fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
FileAccess.Write);
bw = new BinaryWriter(fs);
//startIndex = 0;
retval = dbDR.GetBytes(0, 0, outbyte, 0, bufferSize);

bw.Write(outbyte);
bw.Flush();
// Close the output file.
bw.Close();
fs.Close();
}
// get the end
dbConn.Close();
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
// Display image
//curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
imgBox.ImageUrl = savedImageName;

}

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
bitmaps stored in MS Access normally have a 78 byte OLE Header that you need
to strip off before saving the remaining bytes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:
Hi,

I am trying to save and read an image from MS Access DB based on the
following article:

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

Right now, I saved images without any errors. After reading the ole object
from db, I saved it to C: as file1.bmp and displayed on the web. But it can
not be displayed. After I manually sent the file to wordpad, it shows

System.Byte [ ]

Now I suspect my saving an image might be wrong. The table has 2 columns:
username and userfile. Userfile column shows

.ong binary data

I can not find a way to verify if data was saved ok? But saving does not
report any errors. I am attached my saving and reading codes here to see if
anyone can help?

THanks. –dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
if (dListUsers.SelectedValue == "")
{
lblFileAccess.Text = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFile.FileName;
// only the attched file name not its path
string c = System.IO.Path.GetFileName(curFileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
+ ("VALUES ("
+ (dbClass.DelimString(dListUsers.SelectedValue) + (","
+ ("\'"+rawData + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sSQL, dbConn);
dbCmd.ExecuteNonQuery();
dbConn.Close();
lblFileAccess.Text = "The file has been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
lblFileAccess.Text = "The file has not been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
}

private void btnReadFmDB_Click(object sender, System.EventArgs e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.SelectedValue + "\'";
FileStream fs;
BinaryWriter bw;
int bufferSize = 300000;
//byte[] outbyte;
byte[] outbyte = new byte[300000 - 1];

long retval;
//long startIndex = 0;
//string pub_id = "";

try
{
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sql, dbConn);
dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
while (dbDR.Read())
{
fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
FileAccess.Write);
bw = new BinaryWriter(fs);
//startIndex = 0;
retval = dbDR.GetBytes(0, 0, outbyte, 0, bufferSize);

bw.Write(outbyte);
bw.Flush();
// Close the output file.
bw.Close();
fs.Close();
}
// get the end
dbConn.Close();
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
// Display image
//curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
imgBox.ImageUrl = savedImageName;

}

Nov 17 '05 #2

P: n/a
Hi Peter,

Thank you providing this important info.

I changed my reading as below:

retval = dbDR.GetBytes(0, 78, outbyte, 0, bufferSize);

still can not display. When I opened the saved file in wordpad, I saw
nothing. Before I can see:

System.Byte [ ]

Did I do it wrongly?

-Dale
"Peter Bromberg [C# MVP]" wrote:
bitmaps stored in MS Access normally have a 78 byte OLE Header that you need
to strip off before saving the remaining bytes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:
Hi,

I am trying to save and read an image from MS Access DB based on the
following article:

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

Right now, I saved images without any errors. After reading the ole object
from db, I saved it to C: as file1.bmp and displayed on the web. But it can
not be displayed. After I manually sent the file to wordpad, it shows

System.Byte [ ]

Now I suspect my saving an image might be wrong. The table has 2 columns:
username and userfile. Userfile column shows

.ong binary data

I can not find a way to verify if data was saved ok? But saving does not
report any errors. I am attached my saving and reading codes here to see if
anyone can help?

THanks. –dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
if (dListUsers.SelectedValue == "")
{
lblFileAccess.Text = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFile.FileName;
// only the attched file name not its path
string c = System.IO.Path.GetFileName(curFileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
+ ("VALUES ("
+ (dbClass.DelimString(dListUsers.SelectedValue) + (","
+ ("\'"+rawData + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sSQL, dbConn);
dbCmd.ExecuteNonQuery();
dbConn.Close();
lblFileAccess.Text = "The file has been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
lblFileAccess.Text = "The file has not been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
}

private void btnReadFmDB_Click(object sender, System.EventArgs e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.SelectedValue + "\'";
FileStream fs;
BinaryWriter bw;
int bufferSize = 300000;
//byte[] outbyte;
byte[] outbyte = new byte[300000 - 1];

long retval;
//long startIndex = 0;
//string pub_id = "";

try
{
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sql, dbConn);
dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
while (dbDR.Read())
{
fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
FileAccess.Write);
bw = new BinaryWriter(fs);
//startIndex = 0;
retval = dbDR.GetBytes(0, 0, outbyte, 0, bufferSize);

bw.Write(outbyte);
bw.Flush();
// Close the output file.
bw.Close();
fs.Close();
}
// get the end
dbConn.Close();
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
// Display image
//curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
imgBox.ImageUrl = savedImageName;

}

Nov 17 '05 #3

P: n/a
Dale,
You need to post a "short but complete" (a la MVP Jon Skeet) block of code
that will give people enough information to be able to tell what is not
right. That single line of DataReader code isn't sufficient.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:
Hi Peter,

Thank you providing this important info.

I changed my reading as below:

retval = dbDR.GetBytes(0, 78, outbyte, 0, bufferSize);

still can not display. When I opened the saved file in wordpad, I saw
nothing. Before I can see:

System.Byte [ ]

Did I do it wrongly?

-Dale
"Peter Bromberg [C# MVP]" wrote:
bitmaps stored in MS Access normally have a 78 byte OLE Header that you need
to strip off before saving the remaining bytes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:
Hi,

I am trying to save and read an image from MS Access DB based on the
following article:

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp

Right now, I saved images without any errors. After reading the ole object
from db, I saved it to C: as file1.bmp and displayed on the web. But it can
not be displayed. After I manually sent the file to wordpad, it shows

System.Byte [ ]

Now I suspect my saving an image might be wrong. The table has 2 columns:
username and userfile. Userfile column shows

.ong binary data

I can not find a way to verify if data was saved ok? But saving does not
report any errors. I am attached my saving and reading codes here to see if
anyone can help?

THanks. –dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
if (dListUsers.SelectedValue == "")
{
lblFileAccess.Text = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFile.FileName;
// only the attched file name not its path
string c = System.IO.Path.GetFileName(curFileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
+ ("VALUES ("
+ (dbClass.DelimString(dListUsers.SelectedValue) + (","
+ ("\'"+rawData + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sSQL, dbConn);
dbCmd.ExecuteNonQuery();
dbConn.Close();
lblFileAccess.Text = "The file has been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
lblFileAccess.Text = "The file has not been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
}

private void btnReadFmDB_Click(object sender, System.EventArgs e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.SelectedValue + "\'";
FileStream fs;
BinaryWriter bw;
int bufferSize = 300000;
//byte[] outbyte;
byte[] outbyte = new byte[300000 - 1];

long retval;
//long startIndex = 0;
//string pub_id = "";

try
{
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sql, dbConn);
dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
while (dbDR.Read())
{
fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
FileAccess.Write);
bw = new BinaryWriter(fs);
//startIndex = 0;
retval = dbDR.GetBytes(0, 0, outbyte, 0, bufferSize);

bw.Write(outbyte);
bw.Flush();
// Close the output file.
bw.Close();
fs.Close();
}
// get the end
dbConn.Close();
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
// Display image
//curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
imgBox.ImageUrl = savedImageName;

}

Nov 17 '05 #4

P: n/a
Peter,

Sorry. Enclosed is the related codes based on your advice. I appreciate your
help. -Dale

string curFileName = null;
string savedImageName = "C:\\imageFromDb.BMP";

private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
if (dListUsers.SelectedValue == "")
{
lblFileAccess.Text = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFile.FileName;
// only the attched file name not its path
string c = System.IO.Path.GetFileName(curFileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
FileAccess.Read);
byte[] rawData = new byte[fs.Length];
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
+ ("VALUES ("
+ (dbClass.DelimString(dListUsers.SelectedValue) + (","
+ ("\'"+rawData + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sSQL, dbConn);
dbCmd.ExecuteNonQuery();
dbConn.Close();
lblFileAccess.Text = "The file has been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
lblFileAccess.Text = "The file has not been saved successfully for "
+ dListUsers.SelectedValue + ".";
return;
}
}

private void btnReadFmDB_Click(object sender, System.EventArgs e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationState = ((string)(Application["DBType"])).ToLower();
string sConn = dbClass.Connect(applicationState);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.SelectedValue + "\'";
FileStream fs;
BinaryWriter bw;
int bufferSize = 300000;
//byte[] outbyte;
byte[] outbyte = new byte[300000 - 1];

long retval;
//long startIndex = 0;
//string pub_id = "";

try
{
dbConn = new OleDbConnection(sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sql, dbConn);
dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
while (dbDR.Read())
{
fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
FileAccess.Write);
bw = new BinaryWriter(fs);
//startIndex = 0;
retval = dbDR.GetBytes(0, 78, outbyte, 0, bufferSize);

bw.Write(outbyte);
bw.Flush();
// Close the output file.
bw.Close();
fs.Close();
}
// get the end
dbConn.Close();
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
// Display image
//curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
imgBox.ImageUrl = savedImageName;

}

"Peter Bromberg [C# MVP]" wrote:
Dale,
You need to post a "short but complete" (a la MVP Jon Skeet) block of code
that will give people enough information to be able to tell what is not
right. That single line of DataReader code isn't sufficient.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:
Hi Peter,

Thank you providing this important info.

I changed my reading as below:

retval = dbDR.GetBytes(0, 78, outbyte, 0, bufferSize);

still can not display. When I opened the saved file in wordpad, I saw
nothing. Before I can see:

System.Byte [ ]

Did I do it wrongly?

-Dale
"Peter Bromberg [C# MVP]" wrote:
bitmaps stored in MS Access normally have a 78 byte OLE Header that you need
to strip off before saving the remaining bytes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"dale zhang" wrote:

> Hi,
>
> I am trying to save and read an image from MS Access DB based on the
> following article:
>
> http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
>
> Right now, I saved images without any errors. After reading the ole object
> from db, I saved it to C: as file1.bmp and displayed on the web. But it can
> not be displayed. After I manually sent the file to wordpad, it shows
>
> System.Byte [ ]
>
> Now I suspect my saving an image might be wrong. The table has 2 columns:
> username and userfile. Userfile column shows
>
> .ong binary data
>
> I can not find a way to verify if data was saved ok? But saving does not
> report any errors. I am attached my saving and reading codes here to see if
> anyone can help?
>
> THanks. –dale
> private void btnSaveToDB_Click(object sender, System.EventArgs e)
> {
> if (dListUsers.SelectedValue == "")
> {
> lblFileAccess.Text = "You need to select an user first!";
> return;
> }
> curFileName = myFile.PostedFile.FileName;
> // only the attched file name not its path
> string c = System.IO.Path.GetFileName(curFileName);
> // Read a bitmap contents in a stream
> FileStream fs = new FileStream(curFileName, FileMode.OpenOrCreate,
> FileAccess.Read);
> byte[] rawData = new byte[fs.Length];
> fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length));
> fs.Close();
> // Construct a SQL string and a connection object
> OleDbConnection dbConn;
> OleDbCommand dbCmd;
> string applicationState = ((string)(Application["DBType"])).ToLower();
> string sConn = dbClass.Connect(applicationState);
> string sSQL;
>
> sSQL = ("INSERT INTO UserFiles (UserName,UserFile) "
> + ("VALUES ("
> + (dbClass.DelimString(dListUsers.SelectedValue) + (","
> + ("\'"+rawData + "\')")))));
> try
> {
> // write the visit log entry
> dbConn = new OleDbConnection(sConn);
> dbConn.Open();
> dbCmd = new OleDbCommand(sSQL, dbConn);
> dbCmd.ExecuteNonQuery();
> dbConn.Close();
> lblFileAccess.Text = "The file has been saved successfully for "
> + dListUsers.SelectedValue + ".";
> return;
> }
> catch (Exception excep)
> {
> Debug.WriteLine(excep.Message);
> lblFileAccess.Text = "The file has not been saved successfully for "
> + dListUsers.SelectedValue + ".";
> return;
> }
> }
>
> private void btnReadFmDB_Click(object sender, System.EventArgs e)
> {
> OleDbConnection dbConn;
> OleDbCommand dbCmd;
> OleDbDataReader dbDR;
> string applicationState = ((string)(Application["DBType"])).ToLower();
> string sConn = dbClass.Connect(applicationState);
> // Construct a SQL string and a connection object
> string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
> + dListUsers.SelectedValue + "\'";
> FileStream fs;
> BinaryWriter bw;
> int bufferSize = 300000;
> //byte[] outbyte;
> byte[] outbyte = new byte[300000 - 1];
>
> long retval;
> //long startIndex = 0;
> //string pub_id = "";
>
> try
> {
> dbConn = new OleDbConnection(sConn);
> dbConn.Open();
> dbCmd = new OleDbCommand(sql, dbConn);
> dbDR = dbCmd.ExecuteReader(CommandBehavior.CloseConnectio n);
> while (dbDR.Read())
> {
> fs = new FileStream(savedImageName, FileMode.OpenOrCreate,
> FileAccess.Write);
> bw = new BinaryWriter(fs);
> //startIndex = 0;
> retval = dbDR.GetBytes(0, 0, outbyte, 0, bufferSize);
>
> bw.Write(outbyte);
> bw.Flush();
> // Close the output file.
> bw.Close();
> fs.Close();
> }
> // get the end
> dbConn.Close();
> }
> catch (Exception excep)
> {
> Debug.WriteLine(excep.Message);
> return;
> }
> // Display image
> //curImage = System.Web.UI.WebControls.Image.FromFile(savedImag eName);
> imgBox.ImageUrl = savedImageName;
>
> }
>
>
>

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.