G
Guest
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
implicitly convert type 'long' to 'byte'
for " byte[] rawData = new byte[] {fs.Length};"
My code is attached below. Any suggestion? Thanks. -Dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
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();
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
}
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
implicitly convert type 'long' to 'byte'
for " byte[] rawData = new byte[] {fs.Length};"
My code is attached below. Any suggestion? Thanks. -Dale
private void btnSaveToDB_Click(object sender, System.EventArgs e)
{
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();
return;
}
catch (Exception excep)
{
Debug.WriteLine(excep.Message);
return;
}
}