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
Related
In Asp.net using Visual Basic code I want to be able to query a database after a user inputs search criteria, get the results and display them in a table, with the ability of the user to click/select individual results and delete the corresponding data from the database. How can I do this?
You can do this by utilizing a Datagridview and binding data to it (by using OLEDB for example). Use the WHERE clause in your query to filter the records, based on the user input. (http://www.w3schools.com/sql/sql_where.asp)
The Datagrid has events you can use (delete, select, insert and update event).
See for more information: https://code.msdn.microsoft.com/VBASPNETGridView-19039173
Good luck!
I need help choosing between Telerik RadGrid and DevExpress ASPxGridView for Asp.Net based on unique filtering requirements. The data lives in denormalized Vax files. All data access is via Sql Server stored procedures calling ODBC Connx queries to the flat files. Stored procedure parameters are used to filter the data. Without any filter thousand of records are returned.
I've successfully displayed all records on two test ASP.net pages, one with DevExpress ASPxGridVIew and the other with Telerik's RadGrid. In code I databind each grid to the stored procedure that returns over 26,000 rows. The sproc is called via an Entity Framework function import that fills an IEnumerable<Customer> which becomes the datasource of each respective grid. I'm able to use the filter features of both grids and they seem to work nicely.
My problem is that before the grid filter is applied all of the thousands of rows are returned from the stored procedure. I'd like to intercept the grid's filter parameters and apply them to my stored procedure parameters. That way far fewer records will be accessed.
Can this be done with either 3rd party grid and if so how?
Thanks in advance.
It seems it can be achieved using a RadFilter to the RadGrid. One example here.
But in general, looks like you'd need to add a handler to ItemCommand, and perform the appropriate filter based on the CommandName, for example. You could then just rebind the data.
The Rad Filter will also allow you to use it without being directly tied to another control or datasource. The filter has an option to extract a filter expression in many different forms (linq provider is one of them). You can then apply that expression to your datasource. We are doing something similar. We have a page where we dynamically create the rad filter with the types of fields and filter options. The user then uses the rad filter UI to create the filter based on the desired fields, then we extract a filter expression we can apply to a datatable that is created on the page that shows the data.
Here is the code for extracting the filter expression from the filter:
var provider = new RadFilterSqlQueryProvider();
provider.ProcessGroup(myRadFilter.RootGroup);
var sqlFilterExpression = provider.Result;
I have an ASP.NET project and would like to create a page where my system admins can modify database table data (insert, update, and delete rows).
First, I have a drop down that is databound based on the tables in the database:
DdlTable.DataSource = from x in dc.Mapping.GetTables()
orderby x.TableName.Replace("dbo.", "")
select new {TableName = x.TableName.Replace("dbo.", "")};
DdlTable.DataTextField = "TableName";
DdlTable.DataValueField = "TableName";
DdlTable.DataBind();
DdlTable.Items.Insert(0, "Select a Table");
Next, I would like to have a gridview (or some other data object) that is bound to a table upon selection, and have the columns, insert, update, and delete functionality built dynamically. Can this be done without coding for each specific table?
Obviously, I can create x number of gridviews and datasources, but I would like it to be built dynamically for flexibility and minimal coding.
Essentially, I want to have a simple web-based SQL manager.
Try...
Create a seperate datasource for each table (in code or mark-up, doesn't matter).
Make sure the gridview doesn't have a datasource set when the page loads.
On some event (button click, selectedindexchanged of your dropdown, etc.), set the gridview's datasource to whichever datasource is selected in the dropdown, make sure autogenerate = true, and then databind().
In short - no - you change your tables, you have to change your CRUD - there's no magic bullet.
You can try something like CodeSmith. Or you can just write something yourself -- shouldn't be too difficult, should it? Query the InformationSchema view for your table's fields and you have all of the information you need to build a function in your code-behind to generate the CRUD statements.
I have changed my dbml file like this.
I have deleted all the tables and stored procs.
I added new tables and stored procs from a new database.
In the code-behind, I can access the new tables and stored procs. However, in the LinqDataSource using the same dbContext when I'm trying to configure the LinqDataSource. I can see all the old tables in the wizard drop-down.
How to refresh the the wizard drop-down so that I can select the newly added tables?
Deleting the old LinqDataSourceand adding a new one is not working.
After creating your new dbml, rebuild the solution. The tables should be shown in the wizard then.
I recently began working on a project which has many gridviews on a single page. During creation of a new record, the user needs to be able to add/remove/edit these gridviews and then save to the database at the end. The problem with this obviously is that there is no datasource to bind the data too until after its written to the database.
This data represents a 1..* relationship, which is why the gridview data cannot be written to the database until the parent record has been created first.
The best way I have found so far to solve this is to use viewstate. This solution however does not seem ideal to me. I am also forced to manually create the gridview functionality with OnDeleting, OnUpdating, etc so that I can manage the binding of the viewstate with the gridview.
Does anyone have any suggestions on a better way to manage this situation, it seems like it would be a common thing?
UPDATE:
Keep in mind this data needs to be around throughout postbacks.
Use a DataSet as an intermediate connection to your data source. Fill the DataSet with your data and then bind your GridView to the DataSet setting the GridView DataMember to the name of the table it is supposed to bind to.
As the user updates tables it will add/modify records in the DataTables in the DataSet. When the user is done editing and clicks "Save" your code can then update the database from the datasets, either automatically using a DataAdapter, or manually looking at the RowState of the rows in the DataTables.
Use a DataAdapter and a Dataset. Invoke the fillschema method in the adapter to create de metadata (cols, constraints, relations, etc) in the dataset. bind the data tables created to the different grid views. update manually cheking each row rowstate on each table or call the adapter's update method to do it automatically. If you do it automatically you need to define commands for insert, delete, and update in the adapter.