C#用Linq方法添加数据的时候,数据保存在内存中,SQL文件中没有保存数据
代码using(DataClasses1DataContextDataBase=newDataClasses1DataContext()){Usersuser=newUs...
代码
using (DataClasses1DataContext DataBase=new DataClasses1DataContext ())
{
Users user = new Users();//Users数据库中的一张表
user.UserName = txtAddUserName.Text;
user.Password = txtAddUserPassword.Text;
user.Question = txtAddUserQuestion.Text;
user.Answer = txtAdduserAnswer.Text;
user.Level = comAddUserLevel.Text;
DataBase.Users.InsertOnSubmit(user );
DataBase.SubmitChanges();
MessageBox.Show("已经成功添加用户");
}
外面没有用Try catch 展开
using (DataClasses1DataContext DataBase=new DataClasses1DataContext ())
{
Users user = new Users();//Users数据库中的一张表
user.UserName = txtAddUserName.Text;
user.Password = txtAddUserPassword.Text;
user.Question = txtAddUserQuestion.Text;
user.Answer = txtAdduserAnswer.Text;
user.Level = comAddUserLevel.Text;
DataBase.Users.InsertOnSubmit(user );
DataBase.SubmitChanges();
MessageBox.Show("已经成功添加用户");
}
外面没有用Try catch 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询