I have an app written in c#.
Records from the DB are shown through the auto-generated visual studio code (DataTableAdapter).
this._______tTableAdapter.Fill(this._______SQLDataSet._______);
Now, when I make changes to the DB, not through the DataTableAdaper - but through code on another winform, close it and open another where I have my DataTable filled with adapter, the changes are not shown until I restart my app.
I don't get it, I tryed closing the window using this.Close() and this.Dispose() to release all the resources, so the next time I open it, the code should rebind the new data from the database, but that's not the case...
What am I doing wrong?
Thanks very much for any anwser...
Have you tried explicitly calling DataGridView.Rows.Clear() when you are loading the form?
If that doesn't work, load the form in debug mode, and look at the status of the data every step of the way.
My suggestion/comment may not meet your conditions, but referring to this problem, notice, that you can also modify data in DataSet (not passing the calculations on the server witch every change). If all changes are made - you can call Update method on data adapter which provide data updates for all changed rows.
Anyway - if you want only refresh changes made in other instance - just refrech DataGridView or set DataSource again.
Related
I just started developing my first application using Visual Studio. I have created my own SQL Server database and connected it to a listbox element using a Data Source which is working fine.
However I noticed that after modifying the Data Source (let's say removing a column) I get the error mentioned in the title, which makes perfect sense as obviously the column doesn't exist anymore. But how can I tell Visual Studio that it does not have to look for the removed column anymore?
After receiving the error, I only get directed to this line of code:
this.tableNameTableAdapter.Fill(this.dbNameDataSet.dbtable);
I can't really do anything with this. I've tried to look up the internet for several answers but I couldn't find someone who has encountered the same problem (probably because I used the wrong keywords).
Any advice? Thanks for helping me out!
Additional question: Is this called DataBinding?
You need to reconfigure the TableAdapter after any change in the schema:
configure-a-tableadapters-fill-method
Even better, make the changes in the TableAdapter first and they'll be reflected to the database:
Any changes that you make to the TableAdapter's main Fill method are reflected in the schema of the associated data table. For example, removing a column from the query in the main Fill method also removes the column from the associated data table. Additionally, removing the column from the main Fill method removes the column from any additional queries for that TableAdapter.
In C# I would like to take TWO different projects of windows form application and inserting record in one exe i.e one form and automatic shows the inserted data into another form just like refresh, but I will not using any control like Button Refresh, update.
You have many options to solve your problem.
1) Either use a database, when the 1st app inserts into it, the 2nd app periodically looks for new records in the database, and displays them.
2) Or use a file, in the same way. The first app writes into it, and the second app reads the file periodically and display the rows.
You may need to use a Timer for this purpose.
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 have C# Window Forms project and MySQL ODBC connector to localhost server with all privileges.
I also succeeded to fill dataGridView with data, but the changes I make are not stored back to the database. How do I create save button?
One easy, as in automagical, way to do it is to make a dataset: Menu>Data>Add New Data Source
When the wizard shows, choose Database, DataSet and choose new connection to connect to the database.
When you have the dataset in DataSource window move the dataset over a empty form and VS will create a number of buttons for you including a Save button.
When you have done that you can look at the code to see how it works and adapt that to your own need.
Good luck
edit
based on the comment you made to may answer I can guess that the database adapter you are using doesn't allow the generation of methods that talks directly to the database, hence the errrors dependency on the database connector. That is at least my understanding of this MSDN page
(See headline TableAdapter GenerateDbDirectMethods)
To resolve this you have to set the GenerateDbDirectMethods to false in TableAdapter and only use the InsertCommand, UpdateCommand, and DeleteCommand
When Using SQL Server Reporting Services (client Reports), whenever a Client (rdlc) report Opens Visual Studio Loads entire application datasets,
how to speedup loading this all datasets or how to change the process to only load specific Dataset to use in Report ?
Bulk Insert (or the bcp utility) is your Friend for speedy data imports. Your probably going to have to write a data loader in some language though.
database snapshot could be an option
http://www.sql-server-performance.com/articles/dba/sql_server_database_snapshot_p1.aspx
I may be understanding you question wrong, but on Win Forms I've been loading the needed data sets manually. I basically have a method that loads the proper data from my database, attach the needed data sets to my report viewer using Me.ReportViewer1.LocalReport.DataSources.Add, then I just display my report using Me.ReportViewer1.LocalReport.ReportEmbeddedResource. My reports are embedded resources, but you can load it from a file too, I just can't remember off the top of my head. Once everything is loaded, call RefreshReport, and the report displays. Well, those are the main points, I don't have my code to look, but I know those are the basic steps.
Currently I have been researching how to load data sets on the fly as the user navigates through the report. My work around for this at the moment is to capture the ReportError event, check what report is trying to be displayed from the sender (this is the report viewer object), and load the dataset using the above. The only issue that I am having is that I don't have a loading screen when I am loading the dataset at this point, so it looks like my application freezes. I haven't figured out how to get back to that circular loading screen, but for now, I have a loading window that is displayed while I load. remember, when you get the error, the report trying to be displayed is already set as the local repot, so all you have to do is have a case/if statment checking for the report and loading the data as needed.
Can't you set a default parameter to something which stops much being returned, and only change it to a real one at run-time?