I don't think I need to post any code but if I need to I will.
I have created a Windows Form in Visual Studio that creates a record and saves it into a database. I have also added an update function so that I can change the record and save the new changes.
What I need to know though is how to create some kind of version history. i.e. When I click update, I want it to save the previous version so that I can look back at it. Like a bug tracker has a kind of version control but a lot simpler (hopefully).
Would I need a separate database? Could I have another datagridview that when a record is clicked on (or a button) it will show the history of changes for that record?
I've done many searches online and just can't find how to do it or where to look exactly to find this?
Any help would be greatly appreciated.
Thanks
you are talking about audit trail , take look at this :Link
I know this example for MVC but it's the same idea
you only need one table to track changes of the whole database by using json objects that represent "before" and "after"
Related
When the user double click on a row on the datagridview, the relevant details appear in the textboxes.
User can edit the details and click on Update button to save the updates on the SQL database.
Note : CustomerID is an identity column in the customer table on the database
Please help with the C# code.
Capture of Program
I presume that you've just started to learn WinForms & C#. Firstly, I would recommend that at this stage, you should keep the datagrid view as just a view.
Second, it would be better if you start off by making a simple search button to query your SQL database and populate the textboxes accordingly. Then you can keep on building up your application as you get more sophisticated with how everything works.
Step-by-step dude, nobody is just going to paste an entire code here specifically for you, and even if somebody does, you'll learn nothing.
I have been looking for a while now for a way to do this but nothing seems to be what I am looking for, but all I want is to enter in some data into a DataGridView, save it and then if I want, later load it back up. All the tutorial seem to focus on log in data from some database or something like that when all I want is a grid where I can put things in and add a search filter tool so I can look things up. It is for a project I am doing and I was wanting a way to save and organise data efficiently like how you can as if it was a text document but in a grid with a search filter as well as the way you can send file over to someone else who has the application and read the data. Sorry if I have put it in a confusing way.
I am doing this in Visual Studio 2019 in C#
You could use this one as a staring point. Although such approaches seem to be outdated. (Using datatables etc) Your best bet is using classes for serializing the data to json and sending the json file
This article here describes handling concurrency exceptions. The steps to reproduce the problem are:
Create a new Windows Application project.
Create a new dataset based on the Northwind Customers table.
Create a form with a DataGridView to display the data.
Fill a dataset with data from the Customers table in the Northwind database.
After filling the dataset, use the Visual Database Tools in Visual Studio to directly access the Customers data table and change a record.
Then on the form, change the same record to a different value, update the dataset, and attempt to write the changes to the database, which results in a concurrency error being raised.
Catch the error, then display the different versions of the record, allowing the user to determine whether to continue and update the database, or to cancel the update.
My question is, why does this even happen? Why can't I just save and edit the record from the DataGridView without causing any errors? I'm creating an app with a DataGridView and I'm facing this problem. I need some way to avoid or resolve this error without notifying the user, so whatever they see in the DataGridView gets saved exactly the way thy see it. What's the cause of that error?
The solution turned out to be pretty simple.
All you need to do is reload the data into the DataGridView again after every save.
So the code for the BindingNavigator save button is now:
this.Validate();
this.maintableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.yourDataSet);
this.maintableTableAdapter.Fill(this.yourDataSet.yourtable);
I have no idea why this works, so I need an expert to confirm this. Working solution though.
Thanks to E-Bat for planting this idea in my head.
i'm new to MVC and have to update my model.
I have an SQL Server database already connected to my project, today I add a new column. Now I need to update my MVC code to reflect the change.
Everything online tells me to update the .edmx and .tt files with the Update Model Wizard since they are auto generated, but I cannot find the wizard in VS 2012 so I am at a stand still.
Is this the right way I should be doing this? Any tips would be great...thanks
There are a couple options you can do:
If the database is empty or there isn't a lot of data that you care about, you can drop the database and recreate it.
Manually add the column in the database (after property is in model)
There is something called Code First Migrations. This will allow you to update your database. Here is a tutorial you can look at for this: http://msdn.microsoft.com/en-us/data/jj591621.aspx
Double click the edmx file. This opens the diagram of the database model.
Right click and select "Update Model from Database..."
That will start the wizard you're looking for.
Be aware that not all changes come through automatically.
Most obvious is that columns will not be removed from model just because they're gone from the db. If you're dealing with lots of modifications or deletes rather than additions, it may be best to just drop the model and recreate it (as suggested above by Andrew).
No matter which approach you take, I'd suggest making sure you have all other local source changes committed or shelved before starting because you may need to do an undo check out if EF gets freaked out.
I ended up downloading this update of VS 2012 and repaired. Now I am able to update my model.
I need help. I am currently building data management applications using Winforms and C#. This application has been installed on 10 computers and are connected to one database on the server. Network only in the office.
These applications use the data grid view to display a list of employees.
The main problem now, if users on PC-A has entered a new record or update employee records, data grid view on PC-B is not updated automatically. So if I want to refresh the data grid view on PC-B, I need to press the "REFRESH" button to reload the record.
So the question is now, there are other ways to 'Data Grid View' can be updated automatically?
I do not know what it is named this method, so I hope there is anyone willing to help me in solving this problem. If the my question is already exist, hope someone can give me a link.
Thanks for help :)
In order to achieve what you want, you will need to do some fairly complex architecture work. There is no simple fix here, I am afraid.
The problem is that you want your data girds to update based on an EVENT, however that event occurs outside the application in the database. In order to register that EVENT, you will need to have a class or service which is responsible for handling all INSERTS/UPDATES/DELETES.
If you define all of your tables or views as ARTICLES, you could then have a Publisher / Subscriber model. The Data service would handle all the inserts updates and deletes for the application, and push notifications that an ARTICLE has changed to all the Subscribers for the article. On each page you could have a Class which subscribes to an Article which relates to the data displayed on your data grid, and when it receives a message that the article has been updated, rebinds the data grid to the data source.
Try reading this WIKIPEDIA article on the Observer pattern to get an idea of what the architecture might look like.
http://en.wikipedia.org/wiki/Observer_pattern
You can add Version column to a data base table, then you should ask data base periodically (pooling) to get records with has a greater version than a last received