Auto refresh databinded component after Database update - c#

fellow devs! I need to know a strategy that will allow me to know that the database has been updated so that I can rebind respective controls (DropDownLists in this case. Here is a bit more details:
I have three Combo-Boxes (DropDownLists) on a MDI Parent form. Selecting a value from these combos will allow me to directly jump to the view form for the selected entity. Now, on MDI parent load, these combos are filled up. But once the application is running, anyone from anywhere can edit an entity or add a new one. i need to detect this and somehow cause the combo(s) to reload again.
Using Linq-2-SQL to load the Combos, Backend is a SQL 2005 DB on a SQL 2008 Server.

There's no builtin functionality to do all of this, so you'll have to roll your own.
One possibility I can see is to have a timer that periodically checks whether the items have been updated. You could do this by storing a last updated timestamp somewhere and checking against it. When you detect that the items changed, requery the data and rebuild the combos.

didn't try it, but you may take a look at the Sql Service Broker feature.
From my memory, it can create a file on the file system and you can monitor the creation of this file.
it's the feature used by the ASP.Net cache and its dependencies check.

Related

asp.net web form in multiple browser tabs

I have a grid view and an edit button in the grid view. On edit button click I am opening a new aspx page that has text fields for input the data. When a user copies the URL of the gridview and opens it in a new tab of any browser then click on the edit button for two different records. If the user changes anything in the first tab and submits it. It changes the info for the record on the second tab. It is happening because I am passing userid in session to the form aspx page and session got updated when user opens the second record in the new tab.
Are there only two ways to passing data to aspx page?
using session
using a query string
I don't want to use the query string.
Please help thank you.
You are writing a ASP.Net application, so at the end of the day there is only that much you can do. You can request some things off the browser, but if he actually does it is entirely up to it.
You can make it unlikely to happen by accident, using the HTML Links target property. This requests the browser to re-use any alread open tabs for this record. But that will not prevent a dedicated person from still opening 2 copies.
A pretty simple way to avoid race conditions in general, is the SQL rowversion column. You retreive the rowversion with the rest. You keep it along in a hidden formular field (that is what they are there for). When writing the update, check if it still matches before the write. If yes, you update. If not, somebody has modified the record since then and you reject the update. Can be the same user in another tab, can be another user at the end of the world. Could be that this tab was opened a year ago, surviving on sleep mode. It does not mater - any change trips this protection.

Is it possible to store and later retrieve user-configured WPF/XAML User Controls in SQL

I'm relatively new to .NET development (though I have a lot of Java experience) and I'm trying to see if that what I want to do is possible. I want to create a drag-and-drop template builder so that users can add and position things like comboboxes and textboxes on a gridpanel. Later, users can be assigned an instance of this item to complete.
Here's the ideal process:
Manager creates template using d&d builder to position fields. The number of fields are unknown by me, the programmer (but have a cap, like 15-20) at design time.
On save, this new control (the grid and all of the controls it's wrapped around) is added to a SQL database
Later, the manager assigns an instance of this process to an employee.
The employee opens the item, and queries the DB for the control.
The control is added to a content area (designated by me at design time).
Any existing data is populated into the fields of the control.
At save, the user saves the data for the fields.
For now SQL is non-negotiable. I have already worked out how I'm going to store the data for the fields, I just need to know how to store the actual visual element exactly as configured, and how to display said element to users.
Thoughts?

Refresh WPF usercontrol when navigated to it

I'm new to WPF and now i'm making an app that gets some data from MS SQL Server, places it to the table and allows to modify it. I'm using a M:UI template to make my app look metro-styled. My app structure: MainWindow.xaml and some UserControls placed into it with Itemsource="page" etc. Navigation between UserControls is made with Links and LinkGroups, generated upon MainWindow after successful login.
What I want is to launch a method that gets data from SQL every time I go to any of UserControls. Data is retrieved from server with SQLDataReader and placed to the ObservableCollection (one UserControl - one collection). At this moment my method works fine when I first go to any of UserControls, because it's placed to the constructor of the UserControl class, and I want to get some changes in all my tables when some other table was edited. How can I do this? Is there an event I can raise or some other way to update a table?
Since communicating constantly or background tasks running for server might take overhead and bit of memory wastage so I prefer u start using push notification :) Here's the link that will guide you through the push notification
Push Notification Overview
Raw Notifications
Please go through them design the proper object to pass to you app and to display in the table :) Once you receive a change notification you can map that object to the table you are using .... or read through the sql reader all the records but that wont be a good practice to send all the records so you can go ahead fetch the latest data and append it to the table ... next time when user visits the page it will obviously be refreshed :)

Updating database in MySQL to SQL server in LightSwitch

I have my LS with datasource made in MySQL. I decided to create same database in SQL Server, and when I use the "Update DataSource" of LS, all of my screen objects gone (the textboxes, labels, codes, etc.).
See Image.
Now my question is, how can I retain the screen objects even I change/update my datasource?
Is it possible? Or I have to recreate my screens?
I'm afraid you're going to have to recreate your screen objects. LightSwitch V1 doesn't have the ability to change "change" a screen's data source & still keep the existing screen objects, nor does it have a way to copy/paste screen elements either.
Sorry I had to be the bearer of "bad news".
We're hoping that scenarios like this will have been improved in V2.

Fast way to code forms in C# which is bind to SQL data

I am coming from MS-ACESS world and their programing habits, There was nice utility to make form from table, You can simply hit right click on table and make form for it. Now I looking for something similar for Visual Studio and WinForms. I am trying to develop simple application for which I need to have more then 30 forms for handling data, till now I designed database tables, keys and sprocs in SQL2008 and before I start coding forms for handling data, I asking You for main guidelines how to save my time while coding forms.
Click in VS2008 within the menu bar on Data - Show Data Sources.
In the new window you can select the first icon in the top left to create a new dataSource by help from a wizard.
Just step through it and select the database, tables, views, etc. you like.
When you're finished in the wizard, you can drag and drop the tables from the Data Sources window onto your form. You can also before drag and drop something click on the icon next to the table, view, etc. and change the container type which should be auto-generated.
Starting with these tips it should be quite easy to get a first version to run.
Last but not least:
These wizards create normal code files, which can be viewed and editing like any self written code file. So you can also take a look there to find out which base classes are needed to get all these thing to work to know how you can do some special task manually on yourself.
a simple way is to use a typed dataset (generated by vs) and to bind that to a datagridview.

Categories