I am trying to insert an account in an table in my database. there are no exceptions thrown. but the data is not being added to the database.
Here's the code
public void addAdministratorAccount() {
using (DbDataContext myDb = new DbDataContext(dbPath))
{
var hasher = new Hasher { SaltSize = 16 };
var encryptedPassword = hasher.Encrypt(txtPass.Text);
Administrator adminUser = new Administrator();
adminUser.Admin_FName = txtAddFName.Text;
adminUser.Admin_LName = txtAddLastName.Text;
adminUser.Admin_UserName = txtUser.Text;
adminUser.Admin_Password = encryptedPassword;
myDb.Administrators.InsertOnSubmit(adminUser);
myDb.SubmitChanges();
MessageBox.Show("Administrator Account Has Been Added");
}
Here is my tables Data Context
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Administrators")]
public partial class Administrator : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Admin_ID;
private string _Admin_FName;
private string _Admin_LName;
private string _Admin_UserName;
private string _Admin_Password;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnAdmin_IDChanging(int value);
partial void OnAdmin_IDChanged();
partial void OnAdmin_FNameChanging(string value);
partial void OnAdmin_FNameChanged();
partial void OnAdmin_LNameChanging(string value);
partial void OnAdmin_LNameChanged();
partial void OnAdmin_UserNameChanging(string value);
partial void OnAdmin_UserNameChanged();
partial void OnAdmin_PasswordChanging(string value);
partial void OnAdmin_PasswordChanged();
#endregion
I did not add the whole code since it is long. Why is that my data is not being inserted on the database? I've check the table but it's not there
EDIT: The errors Might be in Located in the DB Path.
Here's my database path
private string dbPath = Application.StartupPath + "\\PatAddSys.mdf";
And here is a photo of where my PatAddSys.mdf is located