Can't Set LinqDataSource InsertParameters From Code Behind
Mar 31, 2010
I have the following code that seems like it should set my insertParameter but everytime an insert happens it uses the default parameter. Do i need to do anything special to make this work?
i have a grdidview control on the .aspx page and i am trying to connect dynamically from code behind and bind the gridview but somehow it throwing me an error... what is wrong with this code?
LinqDataSource LDS_POReport = new LinqDataSource(); LDS_POReport.ContextTypeName = "DataContextDataContext"; LDS_POReport.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSourcePO_Selecting); this.gvReport.DataSource = "LDS_POReport"; //this.gvReport.DataBind();
Update:
after i update the code to this.gvReport.DataSource = LDS_POReport;
it works fine but when i try to sort i get this error:
The GridView 'gvReport' fired event Sorting which wasn't handled.
If I have a Linqdatasource that isn't connected to a a bound control on my page how do I use the data source to read data in the code behind. ie
var query = (from x in linqdatasource select x)
What I actually want to do is create a data array (myArray) within the code, read all of the data from the linqdatasource (selecting 1 field to form tableDataArray), then compare the two arrays and then write (insert) those into in myArray that are not already in the datasource to the datasource (ie execute an insert back on the datasource).
I have LinqDataSource ID="LinqDataSource1" with values - EnableDelete="True", EnableInsert="True" EnableUpdate="True" on my ascx page, furthermore GridView, button a few textboxes, where a fill new values, which I would like save in my database. After click on button I insert new value to the table throught in function stored in ascx.vb page. It is works, but I don't know, how I refresh GridView on ascx page. I tried
LinqDataSource1.DataBind() GridView1.DataBind()
without any good result, I must refresh page manualy (F5).
How can i retrieve the data in linqdatasource in code behind?i have a dynamic database design with column storing the datatype eg. text, int, date.i need to retrieve the value in order to populate the control and bind it.
The second one references the first one, that is each order is assigned to the client. Now suppose I have an .aspx page with a LinqDataSource for Orders table, and a GridView that uses this datasource and displays a table with a following columns:
Order name. Order desc. Client name. Client address.
As far as I understand, the Linq to SQL is designed in such a way, that by default it does not load any associated entities, it only does it when a child property is requested. So, when a page is loaded, the following situation will occur:
First query will retrieve the records from the Orders table. For each row displayed by GridView an additional query will be performed when one of the client properties is requested. Therefore, if we have 100 orders, this means will perform 101 queries instead of one (or even maybe 201, if a query will be performed for each client property)? How to avoid this and make LinqDataSource load all the required fields by a single query? Right now I see the only workaround for this problem - use an SqlDataSource with a join query, that will retrieve all required fields at once.
<asp:LinqDataSource ID="LinqDataSource3" runat="server" OnSelecting="LinqDataSource3_OnSelecting"> </asp:LinqDataSource> And I have ASPxGridView <dxwgv:ASPxGridView ID="ASPxGridView2" ClientInstanceName="ASPxGridView2Client" runat="server" AutoGenerateColumns="False" DataSourceID="LinqDataSource3"> </dxwgv:ASPxGridView>
In this way Im able to add columns dynamically while handling onSelecting event:
protected void LinqDataSource3_OnSelecting(object sender, LinqDataSourceSelectEventArgs e) { MyModelDataContext context = new MyModelDataContext(); ASPxGridView grid = ASPxPageControl1.TabPages[3].FindControl("ASPxGridView2") as ASPxGridView; if(grid.Columns.Count == 0){ GridViewDataTextColumn txtColumn1 = new GridViewDataTextColumn(); GridViewDataTextColumn txtColumn2 = new GridViewDataTextColumn(); txtColumn1.FieldName = "UserId"; txtColumn2.FieldName = "FirstName"; grid.Columns.Add(txtColumn1); grid.Columns.Add(txtColumn2); } e.Result = from u in context.Users select new { UserId = u.UserId, FirstName = u.FirstName }; }
It is all made simply to test cause my idea is to have solution that makes it possible to use inqDataSource as a datasource for de ASPxGridView but join 2 or 3 tables and show results in this grid.
What I want to ask is if its good solution or is there any other better way to present some views made from couple of tables by join?
Second question is that I have Users and Group and I would like to have one table in which I would have two columns Name and Type For groups type would by group and for users type would be user. I dont have such a table in my database Is it possible to create specific class. Create List of objects of that class and fill it using linq query and the use it as linq data source for that grid ?
clas would be:
pseudocode:
Class MyClass { string Type; string Name; }
or is there any other way to create such a table ?
Im trying to build a where clause in c# for a LinqDataSource, but I cant get it to work, heres my code
[Code]....
when I set category to 'Concerts' tyhe where clause is
'Category = Concerts'
this generates an error telling me there is no column called 'Concerts'. I assume I somehow have to enclose the search term in quotes, Ive tried single and double quotes, but nothing works.
So I need to take the literal "SELECT....FROM Bay....WHERE Warehouse=1 and ((BAY LIKE '1.0%' or BAY LIKE '2.0%'))I have set up a linqdatasource on my asp page and I want to bind that to a gridview. Here is the start of the HTML:
ViewState is active and I have a RadioButtonList with DataSourceID to LinqDataSource.If I postback and cause event SelectedIndexChanged, I can read the SelectedValue property, but if the postback is caused by another control, SelectedValue its always empty...Note if I turn ViewState off, works fine, SelectedValue has always a non empty string...
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?
I have a LinqDataSource and a GridView displaying a table. Columns of type xml don't show up. I'd like them to show up something like they do in Sql Server query outputs, with a link to display the clickable xml, though there may be another approach i'm not considering (maybe a styled display of the xml data, etc.). Two things i'd like to know how to do
First, get the xml converted to a string, and display it in the table. Maybe the first 30 chars. Finally, style the xml into something useful, like a clickable link to display the full xml, or a sub-table, or a styled string.
So the following works, and displays a nice table, with edit and delete links. But Xml fields are missing. How would you go about adding support for the Xml fields?
Here's the scenario: ASP.NET 3.5 C# app connecting to an MS SQL backend. I created a LINQ to SQL class called test.dbml and dragged a table called tblTest to the design surface. The table has two columns: the primary key is Email and the other column is Name. Then I dropped a LinqDataSource on the page. The LinqDataSource is not connected to a databound control. It will only being used to retrieve the name associated with a supplied email address. In the Page_Load event, I feed the Where clause:
[Code]....
However, I put a breakpoint inside the ldsAdmin_Selected event and it never hits. With an ObjectDataSource, you can use odsAdmin.Select(); to trigger the ObjectDataSource to actually run and return the info. What's the equivalent method of triggering a LinqDataSource?
I've a gridview bound to linqdatasource1 and a details bound to linqdatasource2 (for searching).
When I update the data on detailsview, my gridview is not updating. I've tried handling various gridview events and databinding the gridview in code but it doesn't seem to work.
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.
I have written the below pages (base of question) to populate my asp.net listview control from an objectdatasource. To allow for easier CRUD commands and to make my application more efficient I want to replace this objectdatasource with a linqdatasource but when I attempt this I receive a binding error which stops my ItemDataBound event firing? I'm basically replacing my objectdatasource with the below linqdatasource...
[Code]....
[Code]....
Am I placing my query within the wrong event? Why does my ItemDataBound event not fire?
I'm using a LinqDataSource with a RadGrid. When I Add a new Grid item and click insert the values are immediately saved to the database.Is there a way where they can be actually not put in the database until I give the command?
the problem is not solved the way i wanted but i go ahead give the credit to : ĆukaszW.pl for his time and effort.
i am using gridview control and a linqdatasource and its all working fine and i have added the functionlity of searchingBySubject and i added WhereParameters and than binding my gridview (see the code below) but somehow its not returning any rows and i see i have number of rows based on what i am searching.
I am writing an ASP.Net web application. I have listview, it's datasource is a LinqDataSource. In my database, I have a staff table and I am trying filter for records by their team using a dropdownlist. This works fine, until I select "All" in the dropdownlist. It returns all staff except for the ones where the teamID is null. How can I return the records where teamID is null?
Orders OrderProducts - An order can have 1 to many orderProducts records associated with it.
What I am trying to do (unsuccessfully) is to implement a GridView search using a LinqDataSource wherein the search returns Order results where any of the OrderProduct.Manufacturer columns contain a search query. I was hoping the following would work, however it seems lambda expressions do not work within a Where clause of a LinqDataSource (in VB):
No property or field 'op' exists in type 'orderProduct' Any clues as to how to get this working within the LinqDataSource definition, or will I have to handle and set up a custom OnSelecting event?
I am binding a GridView with LinqDataSource with AutoDelete functionality enabled. GridView is bound to the Products Table. I have a Products Table and a Category Table with an association on CategoryID. If I try to delete a Category that is referred in the Products Table I cannot do that. Its is totally acceptable, but I want the end user to be notified with some error message. Where to catch this error message?