DataSource Controls :: Most Efficient Database Call?
Jun 24, 2010
I am wondering what the most efficient method is for retreiving a single cell of data from my database. I have a price table in my DB that I just need to look up one price at a time. Currently I load a dataset and call ds.tables(0).rows(0).item(0) for the value. I just want to make sure this is the best way do this.
I want to insert almost 400 rows in one database call in asp.net. I am using .net 3.5 and sql server 2005. What should be the best possible way for doing that?.
I am new to databases and linq, so my problem may be considered trivial. I currently start all my db requests in each class with:
DataClassesDataContext db = new DataClassesDataContext()
Then I proceed to make whatever linq request I need within the method and carry on with the main application logic.
Now, two interesting queries:
1) I believe I have seen people wrapping db usage within 'using'. Such as:
using (DataClassesDataContext db = new DataClassesDataContext()) { ... }
If this is correct, then doesn't it mean that my class can't use a member 'db' variable anymore, but rather those db requests need to be made within each function call? Also, what exactly would happen if I don't use 'using' within the calls?
2) Running my app with SQL Profiler enabled, I see lots of connections opening and closing. Does this means that each
DataClassesDataContext call makes a separate connection? It seems inefficient, so is the right way to actually make the DataClassesDataContext object a static within each class being used?
I am trying to do efficient paging with a gridview without using a datasource control. By efficient, I mean I only retrieve the records that I intend to show.I am trying to use the PagerTemplate to build my pager functionality.In short, the problem is that if I bind only the records that I intend to show on the current page, the gridview doesn't render its pager template, so I don't get the paging controls.It's almost as if I MUST bind more records than I intend to show on a given page, which is not something I want to do.
A sample linq query from MSDN: var expensiveInStockProducts = from p in products where p.UnitsInStock > 0 && p.UnitPrice > 3.00M select p; Does this query select EVERY column from the database table immediately, or does it return some sort of pointer that retieves the actual column data on demand? ie. If there are 50 columns in my table and I only use a single p.UnitsInStock in my actual code, then am I retrieving 50 times more data than I expected?
My kind webhost (1and1) royally asked me to go elsewhere to do something like this.
I have 2 sites. One of them was developed by a .Net programmer. Now I am contracted to implement a PHP site and fetch data from the .Net site.
There is an ASP.Net form that a customer fills and when they hit submit, the data gets stored in SQL Server DB. How do I also store the same data in MySQL parallelly? I cannot directly use some database connectors with ASP.Net since MySQL connectivity is not supported on 1and1 Windows hosting (biz account, no less!).
What I thought of is to publish an RSS feed of entries in ASP.Net site and routinely scrape that data into MySQL on Linux host. It is an overkill, I know. Not efficient.
I have taken over an application where the original developer has used an inordinate amount of user controls and master pages. There are multiple master pages all over the site, with user controls on top of user controls through out the site as well. Some of the user controls are reused, many are not. Would you deem this an efficient or worthy use of user controls and master pages? From my point of view it clutters the project and makes debugging a real chore.
I am trying to find an efficient way of displaying images (about 140x140px) in a webform. We cannot use paging, so we need to display all these images in the same webform.I noticed that facebook (and other sites) lets you display all your images in one page. For a profile qith about 1000 photos, facebook somehow downloads only enough so that the visitor can see images on the screen. Once you scroll, it seems to only download enough so that the visitor can again see something on screen. It works like a good text editor.... instead of displaying a huge file onscreen (like notepad does) and freezing, it only displays enough for the reader to see.
I have a .net 3.5 page that calls a short sql server procedure which compiles fine. When the code is called
from a webpage(.net) it runs the first time it is executed. However on the second time it throws an error saying "There is already an object named 'strPKHoldUp' in the database." StrPKHold is a variable that I declare in the code as seen below.... I have never had a problem before with declaring a variable and having it "save or cache" in the database so you can use it again. Any idea how to solve this? I tried moving the DECLARE statement around a little bit but that didnt. I changed the variable name to something else and it works one time but fails after that...
How do I make a Sqldatasource perform its InsertCommand with VB.NET? Normally, a control on the web page would call this command, but I want to use it in Code Behind.The full routine will be to check and see if the sqldatasource is NOT empty then run an UpdateCommand, but if is empty then run an InsertCommand.
I know the following sproc is vulnerable to SQL injection:
[Code]....
I would like to write a call to this sproc that uses SQL injection to execute the additional command:
[Code]....
That way, I can demonstrate the vulnerability of the sproc to SQL injection and test any revised implementations of the sproc using the same test call.
Problem is, SQL injection is harder than I thought! I just can't seem to do it.
Can anyone provide me with text for the sproc call to execute the additional command?
I want to call my business object class in which I have written my logic when any database status field change, what is the best way we can do, I want notification facility also.
I can do this window service. But there is any best way to acheive this like Notification and call my business object.
I have a problem when trying to validate data on insertion (and possibly update, didnt try it yet) .
I use a formview in insert mode, linking to a custom BLL that then link to a DAL to insert data into a table. The problem is the parameter data is changing between the Datasource inserting event and when the BLL insert method is called. 2 field, that cannot be null in the database, have default value added to them. Bot sure how to explain so well so 'ill post some picture explaining :
This is the form I use, I enter only test in the textbox for the value Nom this is the trace for my DataSource_Inserting event, as you can see, only the "Nom" value is non-null But then, right after the event is done and the call is made to the BLL, the value for "Sexe" and "DateDeNaissance" has been changed to some default value, namely 0 and Jan 1, year 1.
This of course is causing problem because if the user does not provide value for "Sexe" and "DateDeNaissance" then I want the DB to raise an ArgumentException, I do not want to have default value inserted. It seem the problem is in my code, the problem happen before the actual Update call. I'm pretty sure the problem is between the Inserting event and the BLL input parameter but I am still beginning in C# and ASP.NET so I have no clue
When using the DataTable.Load(SQLDataReader) method, if the datatable is a property of a class, the set method is not called to populate the object. For example...
MySQLDataReader = command.ExecuteReader(); if (MySQLDataReader.HasRows)
myObjDataTable.Load(MySQLDataReader); -- The result of this will be 0 rows returned. The "Set" method of the object is never called.
I have a recordset in a gridview that comes from an outer joint that creates null values in the recordsetWhen I write to the database using stored proc defined in datasource I get dbnull error.I'm trying to process the onDeleting event in the code behind but don't know what to write or if that's the best wayI need to call a stored proc and if the last parameters value is null then the stored proc does one thing, if it's no null it does something else.However DBNull doesn't ssem to be working.
Am stuck with this sql stored procedure/asp.net vb.
I want to call the stored procedure and for it to return a true or false if successful ie username and password match.
My stored procedure works fine, and I can call it from my vb, however I stuck as to how I get it to return a result of true or false, 1 , 0. I just get a blank page.
I spent about 60 minutes sifting through search engine listings trying to figure this out and couldn't find an answer, so I decided to make this post for others.
Situation: Using a Stored Procedure to insert a row and return the new row ID, explained here. In my case, I used the Idenity_Scope to return the new row, like so:
[Code]....
Next, following steps as described in link above, went into the dataset XSD page, configured the table adapter to use this stored procedure. By default, it wanted my return value to be set to some value, but I set to allow Null (makes sense, since I don't want to pass the value in, I want to get it out, so it should be null to begin with).
Problem: Where I ran into an issue was in the method to call this stored procedure. The intellisense displayed the prototype it was expecting, basicly like this: