gpt4 book ai didi

c# - LINQ TO SQL 中的查询不插入

转载 作者:行者123 更新时间:2023-11-30 22:31:01 25 4
gpt4 key购买 nike

我在数据库中添加用户时创建了一个简单的查询,但错误是数据没有显示。这是我的代码

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");
}
}

而我的表格数据只显示这个

enter image description here

最佳答案

您需要直接在上下文中设置InsertOnSubmit:

编辑 Using 添加的语句。提醒由 @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();
}

关于c# - LINQ TO SQL 中的查询不插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9435977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com