I have been using excel to view the database tables by binding the sql database views in excel and making a spreadsheet. This works just fine but I want a solution in code.
Is there a way in C# ASP.NET to bind a database view directly to a gridview when given the view name as a string?
***SOLVED*****
I did some more research and found a solution. The main issue was that I didn't want to have to make any business objects or have a stored procedure on my database.
The solution I found was to use an SqlDataSource. I simply set the SqlDataSource.ConnectionString and set the SqlDataSource.SelectCommand to be "Select * From" +MyViewName and then bind the datasource to the gridview.
Using this method I essentially just have to pass in the table/view name and the gridview will be populated from the database directly. This allows me to use the same code and the only thing that needs changing is the database view name string.
Related
I have created a winform app connected to an access database as datasource ,
but now i have added a column in access database & now i have to provide the same field in winform for data entry purpose.
But now in my data source the new field is not visible even after refreshing .
any help in solving this.
The simplest way to do this is to open the dataset, right click on the relevant table adapter (MSdiesTableAdapter), choose Configure and then go through the wizard, adding the new column to the SELECT sql. When you finish the wizard the new column will appear in the datatable.
It won't have appeared in any databound grid etc - you'll also have to go to those grids and do an "Edit Columns" and "Add a New Column", choose "DataBound Column" and pick the new column. You can also, as a quick trick, remove the "DataMember" setting from the bindingsource the grid is bound to, then put it back
Microsoft never intended for DataSets and databases to be perfectly aligned; the dataset is your client side store of info and it may have more or fewer columns than the database, and have stuff it calculates itself locally, or relationships that are different to the database. This is why it needs manually adding and working through
We are trying to figure out how the ReportViewer works and are stuck at the dataset/datasource part. We have a sql-query that connects with 3 different Servers. Is there a simple way to connect a rdlc report to such a dataset in a winform Project that will be shown in Report Viewer?
You have to add a ReportDataSource object to the LocalReport.DataSources Property. The constructor take two parameters.
First the name of the dataset (as it is defined in the rdlc repport), second a datasource object which could be any .Net Collection (ADO.Net DataSet or a simple List of object).
The mapping to the field declared is done in the same way than DataBinding. Just have the same name for the column of the ADO.Net DataSet or the property of the object in the list than the field in the report.
Take a look at
https://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.aspx
I am looking for a good practice in this scenario: I am working with Expression Blend, and want to create a datatemplate for the items in a listbox. I already have project with a model class, lets call it User which will be the holder of data to be displayed in the ListBox items. And what I want to do is to get some sample data containing users that can be bound to the listbox to view the design work in progress.
Microsofts idea with Blend is for it to rid the need of programming skills for designer folks in the process of creating the UI. So I was expecting there to be a way to generate a sample data based on the pre existing code, in this case User class, without any coding.
The proposed solutions that can be done from Blend that I've seen are either, generate an xml-file with elements of type User, and then create a sample data source out of this and bind it to the ListBox. Or, select "new sample data" in the Data tab which will create a collection of a new type with a set of properties that can be managed from Blend. None of theses options are what I am looking for, the first since it will demand the user to precreate an xml file, which is not part of a designers job, the second doesn't meet the requirement of being a data source containing the relevant type, User.
On the Data tab, "Create Sample Data" button, there is an option for "Create Sample Data from Class". As long as the class is already defined and referenced in the project, I think this will do what you want.
Let me preface this by saying I am a beginner as far as .net knowledge.
I am developing a windows form application using tabs in VS2012 in vb. I have bound the datagrid through the designer to a sql server binding source which is populating the data. There are multiple columns in the table and these are split between two tabs with a datagrid on each tab. Both data grids have the same binding source just show different columns.
I created a view within the SQL server to pull in the column names. I think what I want to do and not sure if this is possible but have 2 combo boxes that will be used to filter. One of the would be bound to the view by a dataadapter and then the second to the datagrid binding source.
when the user selects the first combobox(columnname) it would then pull from the datagrid for that column and pull in the valid values to filter. It would then filter the datagridview and refresh it.
Then I am trying to remove the filters through the use of a button.
Can someone please help as I don't even know where to start
You can use Dataview in filtering datasources. You can refer to my answer at this question
I want to be able to reorder my listbox which is bound to my sql ce database by clicking up and down arrow buttons. Since my listbox is populated directly from my database using the entity framework, I think I have to delete the object (from the listbox) and reinsert it (in the row above) if I want to move the item up the list.
I have no view model, my listbox is populated directly from my database in my code like this:
listBoxProperties.ItemsSource = entities.Properties.ToList();
Does my question make sense?
Cheers
ormally you would handle the moving of your list item in your view model which would hold the ObservableCollection the control was bound to - and then that would be reflected in your control via the binding.
It is going to get messy trying to accomplish this dirrectly on the control - which is your only way since your binding to a throwaway copy of the EF properties list.
As your UI dev goes on you are only going to run into more issues like this. I strongly recommend getting a view model in place sooner rather that later.