C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Saving excelsheet in Database using Fileupload C#


Posted Date: 23 Aug 2008    Resource Type: Code Snippets    Category: C# Syntax

Posted By: Tamanna       Member Level: Silver
Rating:     Points: 7



Following is the code snippet for saving a excelsheet file which is being browsed using Fileupload Control of ASP.Net in a Database. Here, i made a Table 'TestTable' in Northwind Database.

Contentlength method of Fileupload is used to get the length of excel file. This length is further used to assign length of a byte[] which will store the Filecontent.

Excelsheet file will be stored as Image in database.


if (FileUpload1.HasFile)
{
int intDocLength = FileUpload1.PostedFile.ContentLength;
byte[] bytDocTemp = new byte[intDocLength];
byte[] IMAGE = FileUpload1.FileBytes;

SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("insert into TestTable(FileExten,FileContent) values (@FileExt,@FileContent)");
cmd.Parameters.Add("@FileExt",SqlDbType.NVarChar);
cmd.Parameters.Add("@FileContent",SqlDbType.Image);
cmd.Parameters["@FileExt"].Value = FileUpload1.PostedFile.ContentType;
cmd.Parameters["@FileContent"].Value = IMAGE;
cmd.Connection = con;
int i=cmd.ExecuteNonQuery();




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Vyas  .  Using Fileupload C#  .  Saving excelsheet  .  Save Excel Sheet in Database with C#  .  Save Excel sheet in database  .  Save Excel files in Database  .  In Database  .  FileUpload with C#  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Convert farenheit to celcius
Previous Resource: Use of min statement in store procedure
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween mask

Contact Us    Privacy Policy    Terms Of Use