I have a complicated issue to solve.
Basically i have a winform application which uses datasets and access files to save data.
Now i have a customer which would like to have the database stored on a sql server.
So .. i made the database in sql and an mdb file with odbc tables attached to it.
And here is the issue.. The program works only in reading and inserting new data. When the user tries to update an existing row the tableadapter goes in concurrency exception.
I can't really understand the reason or how to solve this.
Anybody got any idea or any tips about this issue?
Thank you!
Related
I have made a program with a simple SQL Server .mdf database file.
First: I have connected to the database using SqlConnection and tried to insert some data using SqlCommand. The ExecuteNonQuery returns the number of affected rows successfully for example 1 or 2 ... etc.
But when I use Server Explorer to view the data of the table, there is nothing inserted!?
Then I have used model entity object and DataSource. On SaveChanges function I get also the number of affected rows successfully, but there is no data inserted in Table on viewing it.
When I make a query using Server Explorer, the data will be inserted successfully and I can view it!!? Can you please help me to solve this problem?
thank you marc_s, you gave me a hint "ConnectionString". As I created a database mdf with server explorer, I realized now, there is two mdf files created. One is located in base folder of project and the other located in bin/debug folder. I don't why there is two of them, howerver it solved my problem. Thanks
I'm busy writing a small app and I only want a database to load small amounts of data, in other words I don't need the functionality of SQL.
So I've installed filehelpers, but it seems very limited in the sense that I can read/write and even append data, but it seem impossible to delete one row of data in a table?
Does anyone know how to do this with filehelpers or point me to a different solution where I can just add a local db to my app without any other external software required?
PS. My visual studio does not have the "create local db" from the item selection.
For something like this, I'd use an embedded SQLite database. It gives you the best of both worlds, one file database for local data and most of the features of SQL.
See here: https://sqlite.org/
On their download page, they have lots of stuff and a plugin for VS:
https://sqlite.org/download.html
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 am using a SQL Server Compact database for a project I am working on and have been having a hard time trying to insert data to the database.
My insert statement and everything is working fine and data gets inserted too and I can even do searches for the inserted data (while in the application).
The problem I am having is when I quit and re-run the application, it seems that the data was not inserted into the database and the tables are empty too.
Can anyone let me know where I am going wrong with this?
Thanks
Could it be that the SDF file is overwritten with an empty version whenever you rebuild/run the application?
As Thorsten pointed out, check the Build Action on your SDF file.
I am simply writing an INSERT query to insert values into the table, when I click the submit button the code runs successfully, I don't get any error.
But when I look into the table it shows no data i.e the table is not updated. I don't know why it's happening. Can anyone suggest me.
thank you
I had the same problem if you are using c# windows application probably you have two different data base connection one updated and another still not updated so check your connections and if you are using sql express your database might be replicated in you debug directory so check your debuge folder or run your application from executable file.