• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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
0
kate_y
Asked:
kate_y
  • 5
  • 5
1 Solution
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Type25Commented:
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now