Can I specify a Stored Procedure in my LinqDataSource? - asp.net

I have a Listview that I want to read the results of a Stored procedure. I have created the DBML object with the table and the stored procedure. When I configure my LinqDataSource on the page I cannot specify the SProc - only the Table. Or do I need to do it in the Listview ?
Thanks

Use a custom expression. See section "Using the Selecting Event"
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

Related

Why is datasource handling in query different from handling it in a form?

I am trying to rewrite some form to the lisp page template. In a list page you must use query as a datasource. I have datasource structure in previous (without list page template) and a new one with list page template. But I am now facing a fact that handling datasource in form is different than handling it in a query.
Can someone explayin why it is done this way and how to make a query so there will be almost no difference between datasource before and after using list page template?
For example I have DSs Object, Sub-Object1, Sub-Object2.
Sub-Object1 have a jointSource Object in properties with exist joint and Sub-Object1 have jointSource Object with Inner Join.
Is there some way to set this in Query DS properties or I must add
datasource to datasource and link in more manually.
Well mayby because a form need more information than query?
If you do have a query already.you can drag it to your form as a datasource.
See http://msdn.microsoft.com/en-us/library/gg844014.aspx
The same effect as a datasource with join type in properties can be done on query by using related datasources. So on the query the structure will be more readable than structure on normal form datasources.

Reporting Services and checkboxes to specify WHERE Clause

I have a report embedded in an ASP.NET page. The ASP.NET page has some checkboxes that the user can select which datapoints they want to have show up in the report.
In the code behind file I am setting up part of the WHERE clause to be used in the query based on which checkboxes are checked.
I am putting this string into a report parameter and am not sure how to implement that parameter in the query. Simply placing the parameter in the query thinking the value of the string would come across does not work. I have the correct syntax in the string that is being passed into the report.
How do I properly use a Report Parameter to alter the WHERE Clause of the query?
I am using SQL Server 2005.
Base the report on a stored procedure that takes a BIT parameter for each of the checkbox values.
Build the dynamic SQL in the stored procedure and execute it.

Read a record via code behind for a sqldatasource

suppose i open a sqldatasource for binding on listview.
I would like also to read a field on first record for print it.
How can i access to my sqldatasource from code behind ?
If I where you I would use (typeBeingBound)((ListViewDataItem)e.Item).DataItem in the listView_ItemDataboundEvent.

LINQDataSource - Query Multiple Tables?

I have a database and I've created a DBML Linq-to-SQL file to represent this database. I've created a new aspx page and dropped a linqdatasource and a formview control onto it. When I configure the linqdatasource it gives me the choice only to select * from one table...but I want to pull from multiple tables. e.g. I have tables like simple_person, simple_address, simple_phone, and I want to pull from all of them. How can I accomplish this?
Use a custom query
http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx
See: Using the <asp:LinqDataSource> Selecting Event

Remove a Parameter from DetailsView ItemUpdating

Here's the setup
I have a DetailsView whose DataSource is an ObjectDataSource.
The ObjectDataSource has two methods, select and update, that are stored procedures defined in a TableAdapter.
The Select stored procedure takes 1 parameter--the record id--and returns the fields populated in the DetailsView.
The Update stored procedure takes three parameters--the record id, and two data fields.
The select process works fine.
However, when the I submit the update, I get the following error:
ObjectDataSource could not find a non-generic method Update that has parameters: [all 21 table columns]
I am trying to only pass the (3) necessary fields to the Update stored procedure, but the DetailsView is apparently trying to update using all of the fields it received from Select.
I know that I can access the NewValues collection from DetailsViewUpdateEventArgs, but I don't see a way to remove any of the parameters so that they match the definition in the stored procedure, the TableAdapter, and the ObjectDataSource.
Any ideas?
Perhaps this tutorial can provide some insight. As long as you specify your update method and update parameters in your datasource, this should work fine.
I've been able to work around the problem for now by simply removing the unneeded values from the NewValues collection in the DetailsViewUpdateEventArgs. However, this is not optimal, since I've added another point of failure if there are changes to the stored procedure or the form.
I'd still like to know if a TemplateField can be set to ReadOnly the way that a BoundField can (see comments below Aaron's answer).

Resources