TableAdapter更新失败

时间:2015-03-17 22:47:22

标签: c# sql ado.net dataset tableadapter

我正在尝试从tbUsers表更新userPassword列中的用户密码。

当我单击“确认按钮”时出现以下错误:对象引用未设置为对象的实例 - NullReferenceException未处理

它说我需要实例化一些东西,但我不知道是什么。我已经有tableAdapter实例化了。

谢谢你的帮助!

using System.Data;
using System.Data.SqlClient;
using System.IO;
using Library.DataBase.dsLibraryTableAdapters;
using Library.DataBase;    

tbUsersTableAdapter tableAdapterUsers = new tbUsersTableAdapter();
dsLibrary.tbUsersDataTable dataTableUsers;

private void btnConfirm_Click_1(object sender, RoutedEventArgs e)
{
    tbUsersRow = (dsLibrary.tbUsersRow)dataTableUsers.FindByIdPeopleIdUser(value1, value2);
    tbUsersRow.userPassword = txtNewPassword.Password.ToString(); <- ERROR HERE
    tableAdapterUsers.Update(dataTableUsers);
}

1 个答案:

答案 0 :(得分:0)

好吧,这似乎解决了这个问题。

谢谢大家!

using System.Data;
using System.Data.SqlClient;
using System.IO;
using Library.DataBase.dsLibraryTableAdapters;
using Library.DataBase;    

tbUsersTableAdapter tableAdapterUsers = new tbUsersTableAdapter();
dsLibrary.tbUsersDataTable dataTableUsers;

private void btnConfirm_Click_1(object sender, RoutedEventArgs e)
{
     dataTableUsers = tableAdapterUsers.getDataByUserName(lblUser.Content.ToString());
     tbUsersRow = (dsLibrary.tbUsersRow)dataTableUsers.Rows[0];
     tbUsersRow.userPassword = txtNewPassword.Password.ToString();
     tableAdapterUsers.Update(dataTableUsers);
}