R
Randel Bjorkquist
I'm having a problem pulling out a Microsoft Excel Workbook from a Microsoft
Access database. I know I have the database set up correct, because from
withinside of Access I can insert and retreive the files. What is happening
is that when I try to to them out via my code, I get the error "Index was
outside the bounds of the array".
Can anyone help me?
Thanks in advance,
Randel Bjorkquist
private bool GetTemplateFile(){
bool Successful = false;
DataTable TmpTable = dset_TemplateInfo.Tables["tbl_File"];
DataRow TmpRow = TmpTable.Rows[lstbox_TemplateNames.SelectedIndex];
FileStream fs;
BinaryWriter bw;
int bufferSize = 1000000;
byte[] outbyte = new byte[bufferSize];
long retval;
long startIndex = 0;
try{
olecon_BLOB.Open();
olecom_BLOB.Parameters["FileID"].Value =
int.Parse(TmpRow["FileID"].ToString());
olecom_BLOB.Prepare();
OleDbDataReader myReader =
olecom_BLOB.ExecuteReader(CommandBehavior.SequentialAccess);
while(myReader.Read()){
fs = new FileStream("_tmp.xlt", FileMode.OpenOrCreate,
FileAccess.ReadWrite);
bw = new BinaryWriter(fs);
startIndex = 0;
*******************************************************
THE ERROR HAPPENS HERE
*******************************************************
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
*******************************************************
while(retval == bufferSize){
bw.Write(outbyte);
bw.Flush();
startIndex =+ bufferSize;
retval = myReader.GetBytes(1, startIndex, outbyte, 0,
bufferSize);
}//END OF "while(retval == bufferSize)"
bw.Write(outbyte, 0, (int)retval - 1);
bw.Flush();
bw.Close();
fs.Close();
Successful = true;
}//END OF "while(myReader.Read())"
myReader.Close();
olecon_BLOB.Close();
}//END OF "" TRY-BLOCK
catch(Exception E){
MessageBox.Show(E.Message);
olecon_BLOB.Close();
}//END OF "finally"
return(Successful);
}//END OF "GetTemplateFile"
METHOD --------------------------------------------------
Access database. I know I have the database set up correct, because from
withinside of Access I can insert and retreive the files. What is happening
is that when I try to to them out via my code, I get the error "Index was
outside the bounds of the array".
Can anyone help me?
Thanks in advance,
Randel Bjorkquist
private bool GetTemplateFile(){
bool Successful = false;
DataTable TmpTable = dset_TemplateInfo.Tables["tbl_File"];
DataRow TmpRow = TmpTable.Rows[lstbox_TemplateNames.SelectedIndex];
FileStream fs;
BinaryWriter bw;
int bufferSize = 1000000;
byte[] outbyte = new byte[bufferSize];
long retval;
long startIndex = 0;
try{
olecon_BLOB.Open();
olecom_BLOB.Parameters["FileID"].Value =
int.Parse(TmpRow["FileID"].ToString());
olecom_BLOB.Prepare();
OleDbDataReader myReader =
olecom_BLOB.ExecuteReader(CommandBehavior.SequentialAccess);
while(myReader.Read()){
fs = new FileStream("_tmp.xlt", FileMode.OpenOrCreate,
FileAccess.ReadWrite);
bw = new BinaryWriter(fs);
startIndex = 0;
*******************************************************
THE ERROR HAPPENS HERE
*******************************************************
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
*******************************************************
while(retval == bufferSize){
bw.Write(outbyte);
bw.Flush();
startIndex =+ bufferSize;
retval = myReader.GetBytes(1, startIndex, outbyte, 0,
bufferSize);
}//END OF "while(retval == bufferSize)"
bw.Write(outbyte, 0, (int)retval - 1);
bw.Flush();
bw.Close();
fs.Close();
Successful = true;
}//END OF "while(myReader.Read())"
myReader.Close();
olecon_BLOB.Close();
}//END OF "" TRY-BLOCK
catch(Exception E){
MessageBox.Show(E.Message);
olecon_BLOB.Close();
}//END OF "finally"
return(Successful);
}//END OF "GetTemplateFile"
METHOD --------------------------------------------------