I'm having a moment of stupidness.
I have a Treeview control in WPF, that is displaying a list of Quotes, ie Quote#, Quote Name eg "Q#1000" "Server Quote" This treeview is bound to a collection of objects
public ObservableCollection quoteitems = new ObservableCollection();
Which are loaded from a SQL database via an SQLDataReader which populates the collection. Changes to the Quotes Collection are committed to SQL after calling a QuoteUpdate() method that writes the changes to the collection back to the database.
The problem is, what happens if a another user using the same app changes the Name of a Quote. How can I detect a change to the table, WITHOUT polling the table for updates, or using a timmer to refresh the data in the TreeView?
Am I missing something in binding controls to SQL? Is there a way to bind a control to a table and have updates handled by the control automatically? I see "two way data binding" and that seems to be what I'm after but haven't seen a way to do this with an SQL data source. Or am I having a dumb moment with how I'm thinking about the way SQL actually works!
If you're using SQL Server (version 2005 and above), you can use Query Notifications to monitor changes. Have a look at this article to get a headstart on this.
Related
I am new in vb.net programming. Am facing a problem in database handling. Am using oledb to deal with database, which is MS Access in my project. I am dealing with queries at the time. Now the problem is that my queries are working well on vb form but are not affecting the actual database. For example, when am adding a record, it displays 'record added successfully', the message I have used for my conformation, but the actual database is not displaying the record I just entered and even got the above conformation message as well. I have checked query in sql editor too, its doing well. I have checked locals in vb debug mode, all are containing correct values.
Am not getting what's the reason behind that. Why it is displaying the success message but not modifying the actual database. Same is the case when am firing delete query, till now. I have not tried Update query yet.
Technology - Visual Basic.net with MS Access
Am using Access 2007 and Visual Studio 2013
Please Help by your suggestions
Do the controls on your form have the correct control source, i.e. the database table/query from and to which it should be reading and writing to?
Basically the problem was the gap between my understanding and .Net's working.
Here is the solution.
You can include database in two ways:
1.Either importing it directly to your project from the place, for example using drag and drop, or some other such method.
2.Or, by including it via using wizard.
But, the difference lies in connection string you use in your project, if you give absolute path of database, then you will directly see the alterations in database you have done using your application, even in testing and debugging mode via IDE.
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\xyz.accdb"
But if you are using connection string provide by wizard, for example,
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\xyz.accdb"
what the IDE will be doing is whenever you will be running project for debugging or testing, every time, it will copy the actual database, with its contents as well, in /bin/Debug folder. So, the changes you are performing will only be visible to that copy, not the actual file. So, if you want to verify with the database, like in our case, check the copy of database, which will be present in /bin/Debug folder. You will see the changes there. But, every time you run project for debugging, it will replace that copy with original one.
So, actually I was checking the original database file, not that copy, since the changes were only made to that copy. So that is why I was facing the above problem, not due to any programming fault.
Here is the scenario. Two networks need to talk to eachother. I have an app that has a local database in our environment that the app talks too. It is using bound controls on a datagrid using vb.net. Now we want to move the database to the other network and the only way we can have access is this network is using web services. I have a datagrid that is bound to a database and employee table. The vb.net code using the fill function and dataset embedded sql to display. The save function has code such as me.validate() and .endedit() and then uses the update method to update the database from the grid. I need to strip this out and put it in web methods. What is the easiest way to do this. I know the fill is basically a select statement i can retrieve and return a datatable from the web service, but what would be the easiest way to save from the web method. any ideas would be appreciated. unfortunately this is the way it has to be from the network standpoint.
I have a WPF datagrid successfully bound to a view in a SQL database. BUT, when the data in the SQL table changes the datagrid does not change. Thinking about this, I can't figure out what would trigger an update of the Windows parts (Table Adapter, Dataset, ViewSource, etc). Should that be happening? How do they know when the SQL table has changed? It seems some Windows part would have to re-run (Select * from ...view) repeatedly to get updated. What am I missing?
Look at SqlDependency. From MSDN-> The SqlDependency object represents a query notification dependency between an application and an instance of SQL Server. An application can create a SqlDependency object and register to receive notifications via the OnChangeEventHandler event handler.
I am using Microsoft Visual Basic 2010 Express. I have a WPF-based project. I have a successful connection to a database in Database Explorer, and a working existing Data Source in Data Sources.
I created a datatable from the datasource using this code:
Dim roster_table As New DataTable("AGENT_ROSTER")
I can manipulate this datatable just fine, but I cannot figure out how to save its data to my database (agentroster.sdf) since the connection is on a global level, and isn't declared in this particular window.
How do I update this database from the datatable on this window?
By the way, I tried creating a connection on this window's code, using the exact same connection string as the successful globally-connected database, yet it said that it couldn't connect.
Tough to say given the limited information you provided. You should also note that there are a lot of ways to do this. However the most basic way is to use a table adapter. Once you've set the Update, Insert and Delete commands you call its Update method.
Here's an MSDN article that might help you further
In our server client software in vb6 with SQL2005, On server side one SQL table is continuously updated by data and we need to display data from this same table on client at running time. Pleases help how to access this same table from server and client so that data is continuously updated from server side and records in this table show on client software without error.
Your VB application needs to poll the table on occasion (as often as you need it to) to gather the new data, then display it as needed. Further assistance is going to require more information from you (such as, are you just asking us to write this for you?).
In VB6 you can use a timer control on the form to periodically check and reload the data to the form. If you are using an ADO recordset then reload the recordset with the table data and rebind to your form's values OR if you are using the built-in binding you will have to tell the form to reload and/or rebind. It's been a while since I have done VB6 so my memory on the exact steps is a little rusty.