Welcome to Webhost4life Forum Sign in | Join | Faq

ASP.NET C#

Started by Lord_Death at 04-01-2008 4:34 AM. Topic has 1 replies.

Print Search
Sort Posts:    
   04-01-2008, 4:34 AM
Lord_Death is not online. Last active: 4/1/2008 8:21:36 PM Lord_Death

Not Ranked
Joined on 04-01-2008
Posts 1
ASP.Net C# SQLServer Image upload
Reply Quote
guys i have a pronlem uploading an image into SQl server DB,

the image field in sql sarever DB Table is varBinary(MAX) and below is my code ,

i download the image trough a gridview .

My .aspx.cs code
--------------------------------------------------

if (FileUpload1.FileName != "")
{

// Retriving Extension for Filename.
string fileNameTmp = FileUpload1.FileName;
int extensionIndex = fileNameTmp.LastIndexOf(".");
string fileExtension = fileNameTmp.Substring(extensionIndex);

// Validating the Extension for Filename
if (!fileExtension.Equals(".jpg"))
{
LabelImageType.ForeColor = System.Drawing.Color.Red;
return;
}

SqlDataSource1.InsertCommand = SqlDataSource1.InsertCommand.Replace("@RC_Image", "'" + FileUpload1.FileBytes + "'");

--------------------------------------------------
   Report 
   04-10-2008, 9:17 AM
Jordan is not online. Last active: 9/4/2008 9:31:21 PM Jordan

Top 10 Posts
Joined on 09-20-2005
Chicago
Posts 16
Re: ASP.Net C# SQLServer Image upload
Reply Quote

You didn't include the SQL insert statement you're using, so it's hard to determine exactly why it's not working.  I recommend you put your database code for this file in the code-behind page rather than using a SqlDataSource web control.

There are two different datatype you can use in the database to store images.  You can use varBinary(MAX) as you've used, or you can use image.  The most imporant part is that you send the file to the database as a byte array.  This has an example for SQL 2000, but it will work just as well in SQL 2005.  http://www.codeproject.com/KB/web-image/PicManager.aspx


   Report 
Webhost4life Fo... » General Discuss... » ASP.NET C# » Re: ASP.Net C# SQLServer Image upload

Powered by Community Server, by Telligent Systems