473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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

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
4 3255
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dan glenn | last post by:
(PHP4.3.4) Is it possible to change an image that's in one type (jpg, gif, png) into another type? Especially, I know I can read a gif with GD2, but I really need to be able to save it as a png. Is...
4
by: dale zhang | last post by:
Hi, I am trying to save an image to MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp For save button, I converted his VB to the following C#....
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
6
by: Brad Allison | last post by:
I am using a small Access database as the back end of a VB .NET program. I am not a newbie to Access, but I have never had the need to store pictures until now. I have a field in a Master table...
5
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.