Reputation: 480
I made a C# program with sql database. I created the Form using the drag and drop from the data source. but when I press in save button, the data doesn't save on the database.
the code created automatically is
namespace test3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void tableTest3BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
Validate();
this.tableTest3BindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.test3DataSet);
//this.tableTest3TableAdapter.Update(this.test3DataSet.TableTest3); // I tried to add this line but it also not work !!
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'test3DataSet.TableTest3' table. You can move, or remove it, as needed.
this.tableTest3TableAdapter.Fill(this.test3DataSet.TableTest3);
}
}
}
Do I have to add some code or change properties, By the way I created the database following steps in website and it must be correct.
Upvotes: 2
Views: 8354
Reputation: 1
I had the same problem whilst working through an example in the Tony Gaddis book 'Starting out with C#' in chapter 11 on Databases.
After I had chosen my database objects in the database configuration wizard I got prompted with a window asking if I wanted to copy the database to my application folder....
Well on my second attempt I clicked no and then I tried the save button and it was working. So yeah, give it go.
Upvotes: 0
Reputation: 926
By default in the solution explorer the database is set to COPY ALWAYS to the bin\debug folder which means that the database is alwys overwritten by the one in the application folder.
Solution: You can change this property to DO NOT COPY and copy it yourself if when needed or leave the database out of the project. When asked to bring it in the project when creating a connection, sympy say no. or you should change the connection string directory to the database in the project forlder not in the debug folder. that should work.
Upvotes: 4