Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
Please give exact code in C#.net to import excel sheet,word document in to sql server. please help me out please.....
Posted

1 solution

No. But it isn't difficult:
1) Set up a field in your database to hold it: IMAGE is the one to go for as VARBINARY can only hold 8000 bytes.
2) Read the file, using File.ReadAllBytes[^]
3) Connect to your database, and write the bytes to it using a parametrized INSERT sql statement:
using (SqlCommand cmd = new SqlCommand("INSERT INTO MyTable (wordFile) VALUES (@DATA)", con))
   {
   cmd.Parameters.AddWithValue("@DATA", data);
   cmd.ExecuteNonQuery();
   }
 
Share this answer
 
Comments
Member 7962316 1-Jul-11 7:35am    
what is use of using key word
Member 7962316 1-Jul-11 7:38am    
please give me complet code to read a word document also
OriginalGriff 1-Jul-11 8:26am    
You don't need to read a word document to store it in a database: all you need to do is read the file into an array of bytes. The link I gave you will have an example of how to do that (not that it's exactly rocket science)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900