Re: Field too small
- From: "Jim McGivney" <mcgiv1@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 Sep 2005 19:22:11 -0500
This is the code I use:
private void Page_Load(object sender, System.EventArgs e)
{
// wire the upload button event handler
this.btnUpload.ServerClick += new EventHandler(this.btnUpload_ServerClick);
if (!Page.IsPostBack)
{
// make the table containing the upload controls visible and the datagrid
with the uploaded data invisible
tabUpload.Visible = true;
AnteGrid.Visible = false;
}
} // Page_Load
// ROUTINE: btnUpload_ServerClick
// DESCRIPTION: This routine provides the event handler for the upload
button click event. It is responsible processing the file and displaying the
contents.
private void btnUpload_ServerClick(object sender, System.EventArgs e)
{
string filename = null;
filename = txtUpload.PostedFile.FileName.Trim();
if ((filename.Length > 0))
{
OleDbConnection dbConn = null;
OleDbCommand dcmd = null;
BinaryReader bReader = null;
int filesize;
try
{
// make sure file was specified and was found
filename = txtUpload.PostedFile.FileName.Trim();
if ((filename.Length > 0) && (txtUpload.PostedFile.ContentLength > 0))
{
// get the connection string from web.config and open a connection to the
database
dbConn = new OleDbConnection(@"Jet OLEDB:Database Password=;Data Source="
etc., etc., etc. , ");
dbConn.Open();
// build the command used to add the data to the database
dcmd = new OleDbCommand();
dcmd.CommandText = "INSERT INTO Ante " + "(FileID, Filename, FileSize,
FileData) " + "VALUES " + "(?, ?, ?, ?)";
// create the paramters and set the values for the FileID
string fileid = "12";
dcmd.Parameters.Add(new OleDbParameter("FileID", fileid));
// create the paramters and set the values for the file data
dcmd.Parameters.Add(new OleDbParameter("Filename", filename));
filename = filename.Substring(61); //remove the path
filesize = txtUpload.PostedFile.ContentLength;
string ConnType = txtUpload.PostedFile.ContentType.ToString();
dcmd.Parameters.Add(new OleDbParameter("FileSize", filesize));
txtUpload.PostedFile.SaveAs(filename);
bReader = new BinaryReader(txtUpload.PostedFile.InputStream);
dcmd.Parameters.Add(new OleDbParameter("FileData",
bReader.ReadBytes(filesize)));
// insert the file data
dcmd.Connection = dbConn;
dcmd.ExecuteNonQuery();
}
} // try
finally
{
if (dbConn != null)
{
dbConn.Close();
}
if (bReader != null)
{
bReader.Close();
}
} // finally
//***********
}
else
{
// production code should notify user of upload error here
tabUpload.Visible = false;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
// File1.PostedFile.SaveAs("c:\\temp\\"+Text1.Value);
// bReader
// dcmd.Connection = dbConn;
// dcmd.ExecuteNonQuery();
}
"Paul Clement" <UseAdddressAtEndofMessage@xxxxxxxxxxxxxx> wrote in message
news:oq5rh1tjshgnkmpav9gsrihni3jkq0rgje@xxxxxxxxxx
> On Sun, 4 Sep 2005 17:02:23 -0500, "Jim McGivney"
> <mcgiv1@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> ¤ On a VS.net 2003 aspx page I want to upload a graphic file into an
> Access
> ¤ database. The field name is FileData and the data type is OLE Object
> ¤ (should be good for 1 gig) When I upload a file (gif file about 78 kb)
> I
> ¤ get the message from the server:
> ¤
> ¤ The field is too small to accept the amount of data you attempted to
> add.
> ¤ Try inserting or pasting less data.
> ¤
> ¤ [OleDbException (0x80040e57): The field is too small to accept the
> amount of
> ¤ data you attempted to add. Try inserting or pasting less data.]
> ¤
> ¤ Any help would be appreciated.
> ¤ Jim
> ¤
>
> How are you saving the file to the OLE Object column?
>
> I believe in Jet 4.0 the OLEObject data type supports up to 2.14 GB.
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
.
- References:
- Field too small
- From: Jim McGivney
- Re: Field too small
- From: Paul Clement
- Field too small
- Prev by Date: CodeProvider for SQL
- Next by Date: Re: DataReader and Transactions
- Previous by thread: Re: Field too small
- Next by thread: Cannot add new row to DataSet
- Index(es):