How to extract and display database files into a datagrid

HI,

I stored files into an Access database as data. How do I extract and display the database files into a datagrid using vb.net in a aspx page? so user can click on the file name and open the file.

thanks

kate
kate_yAsked:
Who is Participating?
 
Type25Connect With a Mentor Commented:
Can't do it for you but can give you an idea of how to insert some data into sql

SqlConnection Cnn = new SqlConnection("connection_string_here");
Cnn.Open();

string filePath = Server.MapPath("/yourFiles/" + filename);  // directory and file name you're uploading the file to

string SQL = "INSERT INTO yourTable (filePath) VALUES ('" + filePath + "')";

SqlCommand Cmd = new SqlCommand(SQL,Cnn);

Cmd.ExecuteNonQuery();


There are loads of examples out of how to do this...
Search google for "Upload file ASP.NET"
0
 
Type25Commented:
I think you're best best Kate is to store the files on the file stystem with a (string) location of the file in the DB.

It's far, far simplier and will save space as well as numerous other advantages.

Peice of cake displaying the data in the datagrid too.

0
 
kate_yAuthor Commented:
The thing is i had a file uploading function. I can either upload the files to different folders on the server which will be a lot of different folders or upload to a database.  I thought files in database would be easier to control cause i have to base on different criteria to pull out different files. What do mean by file system? Do u mean by creating different folders on the web server to store files? Do you have to manually put the path into a database? What if it is a large amount of files in different folders?

thanks a lot.

kate
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Type25Commented:
Kate, storing large chunks of data (ie. images or files) in a database is pretty controversial.

Some say it's a good idea other avoid it like the plauge.

The file system (yep files and folders) are the way to go, at the end of the day holding files is what they are designed to do.

Storing the physical path to the files is easy.  

1) Upload to your server and you'll already know what the path is

2) Set the criteria in database so you can still query it in exactly the same way

3) Simply pull down the path from your DB and set that as you link

..and away you go.

Also, you won't need to put them in seperate folders at all, as long as the DB knows what the physical path is that's good enough.

Advantages
-------------

Don't have to clog up your DB
Quicker DB backups
Easier to manipulate
Endless other aswell..


Good luck Kate!
0
 
kate_yAuthor Commented:
thanks a lot. but if you many files uploaded into a folder, how to put the path into the database at the same time as uploading although we know the path. Do we have to go into the database table and key in the path?? We need to upload the files and display the uploaded file listing in the next page so user can view the uploaded files and download the files.

thanks
0
 
Type25Commented:
Kate

In steps  (psudo style)

1) Upload image into directory on your server

2) Check file exists

3) Insert your data for that file in your database  (with an insert statement, you don't need to manually go in there..)

4) Redirect to next page

5) Read database row back and insert hyperlink.NavigateURL to the path you retreive from the DB
0
 
kate_yAuthor Commented:
Could you give me example on the insert statement especially on what value to represent the path ( directiory and file name) ?

thanks

0
 
kate_yAuthor Commented:
thank you very much..i will try that
0
 
Type25Commented:
Wow...  A  'B' was slightly unfair......

0
 
kate_yAuthor Commented:
hmm, i just think your solution is not exactly what I need since i've already stored files in db. but i can change the grading if it bothers you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.