我正在尝试在我的数据库中的表中插入一个帐户。没有例外。但数据没有添加到数据库中。
这是代码
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");
}
这是我的表数据上下文
[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
我没有添加整个代码,因为它很长。 为什么我的数据没有插入数据库?我检查了桌子,但它不在那里
编辑:错误可能位于数据库路径中。
这是我的数据库路径
private string dbPath = Application.StartupPath + "\\PatAddSys.mdf";
这是我的PatAddSys.mdf所在位置的照片