Reputation: 16117
I've created a simple query in adding users in the database but there error is that the data is not showing. here's my code
private void button1_Click(object sender, EventArgs e)
{
using (DataClasses1DataContext myDbContext = new DataClasses1DataContext(dbPath))
{
//Instantiate a new Hasher Object
var hasher = new Hasher();
hasher.SaltSize = 16;
//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);
Account newUser = new Account();
newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
// Replace AccountTableName with the actual table
// name found in your dbml's context
myDbContext.Accounts.InsertOnSubmit(newUser);
myDbContext.SubmitChanges();
MessageBox.Show("XD");
}
}
And My Table data shows only this
Upvotes: 2
Views: 1427
Reputation: 37533
You need to set the InsertOnSubmit
directly on the context:
Edit: Using statement added. Reminder courtesy of @David Khaykin
using (DataClasses1DataContext myDbContext = new DataClasses1DataContext(dbPath))
{
//Instantiate a new Hasher Object
var hasher = new Hasher();
hasher.SaltSize = 16;
//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);
Account newUser = new Account();
newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
newUser.accnt_Position = encryptedPassword;
// Replace AccountTableName with the actual table
// name found in your dbml's context
myDbContext.AccountTableName.InsertOnSubmit(newUser);
myDbContext.SubmitChanges();
}
Upvotes: 3