:) I've started with project of creating some program for Library. I mean, it is a simple program which has login form and some features for admin. Also, I've done database (everything is done with Visual Studio 2013), SQL Service-based Database. I followed some Youtube tutorials and now when I added button for adding users in database I run into "problem". This is code for Add button:
private void btnAdd_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["Library.Properties.Settings.KnjiznicaDBConnectionString"].ConnectionString;
string query = "INSERT INTO User VALUES(@Name,@Surname,@Year,@Mail)";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(query, connection);
{
connection.Open();
command.Parameters.AddWithValue("@Name", txtName.Text.Trim());
command.Parameters.AddWithValue("@Surname", txtSurname.Text.Trim());
command.Parameters.AddWithValue("@Year", txtYear.Text.Trim());
command.Parameters.AddWithValue("@Mail", txtMail.Text.Trim());
command.ExecuteScalar();
}
}
Now, I know that user is added into database, because I can see it in DataGridView which is also in Form, but when I check directly in Database (I mean in Server Explorer->Database_name->Tables->User (Show Table Data)), that new user is actually not added there. And no matter if I exit Visual Studio, as long as I don't shut down computer, that new User will be in DataGridView but not in "Database". And when I restart computer and start Visual Studio again, new user won't be even in DataGridView. Only permanent users are those that I add directly through Show Table Data or with New Query also in Server Explorer. I would like to know what should I correct so all users added through the code and Form are implemented in "real Database" not just DataGridView. Thanks :)