473,725 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Cli ck(object sender, System.EventArg s e)
{
if (dListUsers.Sel ectedValue == "")
{
lblFileAccess.T ext = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFi le.FileName;
// only the attched file name not its path
string c = System.IO.Path. GetFileName(cur FileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
FileAccess.Read );
byte[] rawData = new byte[fs.Length];
fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
+ ("VALUES ("
+ (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
+ ("\'"+rawDat a + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection (sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sS QL, dbConn);
dbCmd.ExecuteNo nQuery();
dbConn.Close();
lblFileAccess.T ext = "The file has been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine (excep.Message) ;
lblFileAccess.T ext = "The file has not been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
}

private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.Sele ctedValue + "\'";
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(sq l, dbConn);
dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
while (dbDR.Read())
{
fs = new FileStream(save dImageName, FileMode.OpenOr Create,
FileAccess.Writ e);
bw = new BinaryWriter(fs );
//startIndex = 0;
retval = dbDR.GetBytes(0 , 0, outbyte, 0, bufferSize);

bw.Write(outbyt e);
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.W ebControls.Imag e.FromFile(save dImageName);
imgBox.ImageUrl = savedImageName;

}

Nov 17 '05 #1
4 3300
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_Cli ck(object sender, System.EventArg s e)
{
if (dListUsers.Sel ectedValue == "")
{
lblFileAccess.T ext = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFi le.FileName;
// only the attched file name not its path
string c = System.IO.Path. GetFileName(cur FileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
FileAccess.Read );
byte[] rawData = new byte[fs.Length];
fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
+ ("VALUES ("
+ (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
+ ("\'"+rawDat a + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection (sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sS QL, dbConn);
dbCmd.ExecuteNo nQuery();
dbConn.Close();
lblFileAccess.T ext = "The file has been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine (excep.Message) ;
lblFileAccess.T ext = "The file has not been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
}

private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.Sele ctedValue + "\'";
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(sq l, dbConn);
dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
while (dbDR.Read())
{
fs = new FileStream(save dImageName, FileMode.OpenOr Create,
FileAccess.Writ e);
bw = new BinaryWriter(fs );
//startIndex = 0;
retval = dbDR.GetBytes(0 , 0, outbyte, 0, bufferSize);

bw.Write(outbyt e);
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.W ebControls.Imag e.FromFile(save dImageName);
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_Cli ck(object sender, System.EventArg s e)
{
if (dListUsers.Sel ectedValue == "")
{
lblFileAccess.T ext = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFi le.FileName;
// only the attched file name not its path
string c = System.IO.Path. GetFileName(cur FileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
FileAccess.Read );
byte[] rawData = new byte[fs.Length];
fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
+ ("VALUES ("
+ (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
+ ("\'"+rawDat a + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection (sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sS QL, dbConn);
dbCmd.ExecuteNo nQuery();
dbConn.Close();
lblFileAccess.T ext = "The file has been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine (excep.Message) ;
lblFileAccess.T ext = "The file has not been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
}

private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.Sele ctedValue + "\'";
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(sq l, dbConn);
dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
while (dbDR.Read())
{
fs = new FileStream(save dImageName, FileMode.OpenOr Create,
FileAccess.Writ e);
bw = new BinaryWriter(fs );
//startIndex = 0;
retval = dbDR.GetBytes(0 , 0, outbyte, 0, bufferSize);

bw.Write(outbyt e);
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.W ebControls.Imag e.FromFile(save dImageName);
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_Cli ck(object sender, System.EventArg s e)
{
if (dListUsers.Sel ectedValue == "")
{
lblFileAccess.T ext = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFi le.FileName;
// only the attched file name not its path
string c = System.IO.Path. GetFileName(cur FileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
FileAccess.Read );
byte[] rawData = new byte[fs.Length];
fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
+ ("VALUES ("
+ (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
+ ("\'"+rawDat a + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection (sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sS QL, dbConn);
dbCmd.ExecuteNo nQuery();
dbConn.Close();
lblFileAccess.T ext = "The file has been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine (excep.Message) ;
lblFileAccess.T ext = "The file has not been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
}

private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.Sele ctedValue + "\'";
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(sq l, dbConn);
dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
while (dbDR.Read())
{
fs = new FileStream(save dImageName, FileMode.OpenOr Create,
FileAccess.Writ e);
bw = new BinaryWriter(fs );
//startIndex = 0;
retval = dbDR.GetBytes(0 , 0, outbyte, 0, bufferSize);

bw.Write(outbyt e);
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.W ebControls.Imag e.FromFile(save dImageName);
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:\\imageFromD b.BMP";

private void btnSaveToDB_Cli ck(object sender, System.EventArg s e)
{
if (dListUsers.Sel ectedValue == "")
{
lblFileAccess.T ext = "You need to select an user first!";
return;
}
curFileName = myFile.PostedFi le.FileName;
// only the attched file name not its path
string c = System.IO.Path. GetFileName(cur FileName);
// Read a bitmap contents in a stream
FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
FileAccess.Read );
byte[] rawData = new byte[fs.Length];
fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
fs.Close();
// Construct a SQL string and a connection object
OleDbConnection dbConn;
OleDbCommand dbCmd;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
string sSQL;

sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
+ ("VALUES ("
+ (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
+ ("\'"+rawDat a + "\')")))));
try
{
// write the visit log entry
dbConn = new OleDbConnection (sConn);
dbConn.Open();
dbCmd = new OleDbCommand(sS QL, dbConn);
dbCmd.ExecuteNo nQuery();
dbConn.Close();
lblFileAccess.T ext = "The file has been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
catch (Exception excep)
{
Debug.WriteLine (excep.Message) ;
lblFileAccess.T ext = "The file has not been saved successfully for "
+ dListUsers.Sele ctedValue + ".";
return;
}
}

private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
{
OleDbConnection dbConn;
OleDbCommand dbCmd;
OleDbDataReader dbDR;
string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
string sConn = dbClass.Connect (applicationSta te);
// Construct a SQL string and a connection object
string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
+ dListUsers.Sele ctedValue + "\'";
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(sq l, dbConn);
dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
while (dbDR.Read())
{
fs = new FileStream(save dImageName, FileMode.OpenOr Create,
FileAccess.Writ e);
bw = new BinaryWriter(fs );
//startIndex = 0;
retval = dbDR.GetBytes(0 , 78, outbyte, 0, bufferSize);

bw.Write(outbyt e);
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.W ebControls.Imag e.FromFile(save dImageName);
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_Cli ck(object sender, System.EventArg s e)
> {
> if (dListUsers.Sel ectedValue == "")
> {
> lblFileAccess.T ext = "You need to select an user first!";
> return;
> }
> curFileName = myFile.PostedFi le.FileName;
> // only the attched file name not its path
> string c = System.IO.Path. GetFileName(cur FileName);
> // Read a bitmap contents in a stream
> FileStream fs = new FileStream(curF ileName, FileMode.OpenOr Create,
> FileAccess.Read );
> byte[] rawData = new byte[fs.Length];
> fs.Read(rawData , 0, System.Convert. ToInt32(fs.Leng th));
> fs.Close();
> // Construct a SQL string and a connection object
> OleDbConnection dbConn;
> OleDbCommand dbCmd;
> string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
> string sConn = dbClass.Connect (applicationSta te);
> string sSQL;
>
> sSQL = ("INSERT INTO UserFiles (UserName,UserF ile) "
> + ("VALUES ("
> + (dbClass.DelimS tring(dListUser s.SelectedValue ) + (","
> + ("\'"+rawDat a + "\')")))));
> try
> {
> // write the visit log entry
> dbConn = new OleDbConnection (sConn);
> dbConn.Open();
> dbCmd = new OleDbCommand(sS QL, dbConn);
> dbCmd.ExecuteNo nQuery();
> dbConn.Close();
> lblFileAccess.T ext = "The file has been saved successfully for "
> + dListUsers.Sele ctedValue + ".";
> return;
> }
> catch (Exception excep)
> {
> Debug.WriteLine (excep.Message) ;
> lblFileAccess.T ext = "The file has not been saved successfully for "
> + dListUsers.Sele ctedValue + ".";
> return;
> }
> }
>
> private void btnReadFmDB_Cli ck(object sender, System.EventArg s e)
> {
> OleDbConnection dbConn;
> OleDbCommand dbCmd;
> OleDbDataReader dbDR;
> string applicationStat e = ((string)(Appli cation["DBType"])).ToLower();
> string sConn = dbClass.Connect (applicationSta te);
> // Construct a SQL string and a connection object
> string sql = "SELECT UserFile FROM UserFiles WHERE Username =\'"
> + dListUsers.Sele ctedValue + "\'";
> 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(sq l, dbConn);
> dbDR = dbCmd.ExecuteRe ader(CommandBeh avior.CloseConn ection);
> while (dbDR.Read())
> {
> fs = new FileStream(save dImageName, FileMode.OpenOr Create,
> FileAccess.Writ e);
> bw = new BinaryWriter(fs );
> //startIndex = 0;
> retval = dbDR.GetBytes(0 , 0, outbyte, 0, bufferSize);
>
> bw.Write(outbyt e);
> 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.W ebControls.Imag e.FromFile(save dImageName);
> 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
6577
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 that possible? -dg
4
2395
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#. But the compiler complains: C:\Inetpub\wwwroot\passwordProtectCSharp\adminUserFile.aspx.cs(333): Cannot
3
3636
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 application, while I am doing for web. I can only find Image from web forms control and HTML control. This may be the root cause of my problem. For read button, I converted his VB to the C#. But the compiler complains:
1
5414
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 web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but I can;t convert the image. I certainly don't want to upload it the the server filesystem, convert...
6
1412
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 named "Picture" and I have set the Date Type as OLE Object. I know that this might be the wrong newsgroup to post this to, but I was wondering if this is the correct data type to handle pictures. I use the following to store the pic in the...
5
14610
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 saving to a file on HDD, then loading it as binary) Does anyone know how to convert an image into a string & have any pointers to information on how the image would look when in the string (Like bit patterns, etc)?
6
8117
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 picture of themselves to their profile... I admit that I'm a newbie... but this is how I understand this:
8
47939
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 that image in grayscale format.How do i do that.It still saves in true color format. -i used picturebox1.image.save() method -i tried to convert an 8-bit image into grayscale but was unable to do it.
0
10772
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.