473,237 Members | 1,086 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,237 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 3247
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.