Bind images to GridView from database without using handler or httphandler - c#

have read many article and most of the article suggest httphandler or handler for image binding to gridview from SQL Server.
Is it possible to bind images from database to gridview without httphandler or handler?.
If yes than provide me sample code
My table schema: Table Name:- ImageGallery
Column Name DataTypes
Photo image
The above table stored the images in <Binary data>

Is it possible? Yes. Is it a good idea? Not at all, and here's why. An HttpHandler is a way of providing a virtual URL for the image. This allows the browser to handle the GET requests on its own, in an order that's efficient, and asynchronously. This further means that the initial GET request isn't burdened down with conceivably MB's of images.
The idea of a website is that it's more efficient to make a lot of smaller requests asynchronously than it is to make one massive request. Why? Because you're already at a disadvantage to provide the user with a good experience when disconnected from the server. Adding insult to that injury by making a massive request that could take minutes, isn't going to add to their joy.

Instead of storing image as Binary datatype in database, U can try an alternate Solution.
1. Make the column datatype as varchar or nvarchar.
2. Store your image in a seperate folder.
3. Fetch the url for that Image.
4. Save it in the Database.
5. Now in your gridview mention tha column data according to ur wish.
6. During Runtime the URL will refer to the content and the image will
be displayed in your Gridview.

Related

Email Images are not getting rendered.

My emails have images that come from database.
So, when I change the images the Images that are shown on my email will change
but the problem is that the images that are displayed are still the old one.
But If I go into the DOM and copy the src of the image and paste it into the address bar the downloaded image is the new image.
Its like there is some sort of cache problem or something. So I cleared the system cache but the image rendered is still the old one
Check these things
1. Server side - Are you clearing all the objects after sending the data to the client?
2. Client side - try by clearing the cache or Make sure you are having images with different names
Suggestion: Please update your question with client side and server side code so that we can guide you better.
It is not a cache problem. In .NET framework there is a copy of the database which gets created at your end to fetch the data at runtime. Due to this you're not getting the updated images from the DB.
To get the updated images, make sure your code accesses the database and fetches the images EVERY-TIME you need.
The key is to get the data directly from the database before displaying.
Also, provide more details for better solutions.

Loading data for GridView from DB, the fastest way for displaying huge amounts of data?

I'm working on a web page that should display huge amounts of data in a GridView.
Obviously I would use some sort of paging.
What I want to know is the best way of doing such a thing, what is the norm?
Should I connect to database each time for every page of GridView? Should I connect to database one time for the first page and load the rest of the data in some kind of background task? Should I load a few pages of data in advance, in the background, to lessen users waiting time?
Any advice is appreciated.
Do keep in mind I'm relatively new to programming and thank you!
Just compare the probability of getting full set of your data for your users first to choose appropriate solution:
if the chance that user need your second page not a big (last news, relevant search results, etc) - do not load all your data. Just load first page only.
if your data are processes sequentialy and they are dependent, so you really know taht after first page user should/must proceed to next page - review solution to load your data for next page in backgroud thread while user works with data of current page (process tasks or documents, approve orders, etc).
if your solution means - your users can randomly navigates to pages in your grid and do this very often (each user need to visit at least several pages randomly) - review solution to load all data into cache and generate pager using cached local data.
Hope this helps.
Use virtualization of Control you use - any grid or lists! Thats important and #1
Set a middle-tier service, that helps you to loads from DB only visible +/- few rows up and down. You can do it via cursors in query, or a much simpler via LINQ extensions wirh .Skip(count) and Take(count) -- that can helps you how many rows you realy read from which position of set (or you can see with LinqPad how it can be transformed in T-SQL if you don't use any ORM)
Don't sort or filter your set on Control (grid or listvew), do it via query on DB side - its a lot times faster(!) with their indexes in DB
Use a SQL Server stored procedure for fetch huge data also send 2 extra parameter paging Page Number, Page Size and return total count from procedure.
Pagination with the stored procedure

Create and store database locally with asp.net

I have a small website with couple different forms inserting data to sql. But the users have problem with it. The problem is that they seem to be going through them too fast that its not recording everything.
So i am trying to see if there was a way to store all the data locally and have it insert to sql at the end when they are done filling out forms. Is this possible?
For example:
I have a form that have 5 fields but 2 are auto populated and 1 entered manually and 2 are being inserted using bar code scanner. The bar code scanner is the last value required before being inserted, so i was hoping there was a way to insert that into locally store access database (not seen by anyone) and when they press "Finish" all that data from access will be inserted into sql.
Hope i painted the picture clear enough.
Let me know any and all possibilities.
EDIT: Here is the aspx and .cs, hope this helps. Yes i realize that i have validation for the bar code, but not sure why its slow. And i may have stuff cluttered. So please bear with me.
Sounds like you need to put that data in application session or cache and then flush the data to db.
Here are some other choices though:
Flat files (simply serialize your objects, use protobuf)
Use Embeded Db: SqlLite, VistaDb, Sql Server Compact...
Store data in the browser via localstorage (dom storage, this is html 5 feature)

After import of Excel data, big post of form with the values

I'm currently developing a web application (C#, ASP.NET MVC) which going to let users upload there own data by Excel files to the SQL Server database. In most of the cases the Excel files will have more than 2000 rows with 5 columns.
To archive this a was thinking about the following solution the main key is performance:
User uploads a excel file with 2000 rows.
The web application returns the rows from the excel file in json, jQuery will do a validation and some calculations on the values, if the values are invalid he will pop-up with some suggestions. At the end jQuery appends the data to a form (10000 textboxes)
User can make changes and needs to improve the invalid data, and does a submit
The web application uses SqlBulkCopy (with the posted data) to a merge table
Stored procedure will merge it to the final table
Is this a good solution, are there better approaches? Is it possible to post 10000 textboxes at one time?
Thanks!
The first part is fine, but the second step is what gets me. That seems not only like it could be a performance nightmare, but it would definitely be a UI nightmare. The solution I would suggest is let the user know which rows have issues and have them fix them in Excel. You then have the option of either adding the rows that were good, saving the file for later use or just discarding it all together. The other steps look good to me as well.
I'm not aware of a limit to how many textboxes can be added to a web page, but like I said, it will be a UI nightmare when there already exists a platform that can make this easy for the user (Excel).

ASP.NET page content in database vs file performance?

I am creating a site whose content is dynamic and has images in it.
What/How much performance hit will my DB (MSSQL) take if I save content/Images in DB?
I am just trying to understand what kind of problems I may run into.
I appreciate any responses.
Thanks!
If you keep content (e.g. images) outside of the database, you can let IIS serve this content directly without calling ASP.NET at all (and as a consequence, no database access is needed).
You can even put static content on a different server is you have huge load (like here on StackOverflow).
So if you need to scale in any way, keep static content outside of both ASP.NET and database.
In the company where I'm employed we are using a custom-made CMS.
It renders content and controls for a page dynamically. The content are stored in a table for all pages, (each page has one main content), and other tables store information regarding UserControls, path to it, and which properties should be set with which value via reflection.
The performance is good, even for lets say 10 dynamically created controls. Our biggest client's page has about 70k hits a day and there is no performance problem. The page renders really fast.
Storing the images in your database can also work.
Just keep in mind that you need to use server-side caching for your images (e.g. get them via a generic handler *.ashx and use chaching there) and hope that your imageurl gets recognized for clientside caching.
If you want to be sure, expose your images directly on a dedicated image application. (e.g. www.foobar.com is your URL, then you can create images.foobar.com and store all your images there)
If would definetly advise to store often used images there, like images for the layout, or userpictures (if you are using a forum, or some kind of web application that uses several pictures all the time). But there is nothing wrong with storing not often used pictures in the database (user related uploads et cetera).
If you store your images in DB, database size will increase and this will result in slower DB queries. Better store on other media and guide your DB to do the stuff for you.

Categories