C# 为什么我的DataGrid没有正确填充密码?

C# 为什么我的DataGrid没有正确填充密码?,c#,wpf,datagrid,ado.net,C#,Wpf,Datagrid,Ado.net,我有以下代码: private void FillData() { try { // this is the adapter dataAdapter = new SqlDataAdapter("Select username, isnull(password,'') from Credentials", connectionString); SqlCommandBuilder cmb =

我有以下代码:

         private void FillData() {
        try {
            // this is the adapter
            dataAdapter = new SqlDataAdapter("Select username, isnull(password,'') from Credentials", connectionString);

            SqlCommandBuilder cmb = new SqlCommandBuilder(dataAdapter);

            // populate new data and bind it.
            DataTable table = new DataTable();
            dataAdapter.Fill(table);
            bindingSource1.DataSource = table;

            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
        }
        catch (Exception e) {
            MessageBox.Show("Error " +e);
        }

    }

    private void ManualGeneratedDGF_Load(object sender, EventArgs e) {
        dataGridView1.DataSource = bindingSource1;
    }

    private void button1_Click(object sender, EventArgs e) {
        bindingSource1 = (BindingSource) dataGridView1.DataSource;
        DataTable ds = new DataTable();
        ds = (DataTable) bindingSource1.DataSource;
        dataAdapter.Update(ds);
    }
我不明白为什么在单击Save按钮时,上面的代码没有正确填充。我在eh datagrid中有用户名和密码,但当我单击“保存”按钮时,它会正确插入用户名而不是密码?

只需更改这一行即可

dataAdapter = new SqlDataAdapter("Select username, isnull(password,'') from Credentials", connectionString);

或者无论您在哪里使用
密码
都要使用方括号,因为它是服务器的保留字。
告诉我它是否有效。

我发现问题是“isnull(密码)”。但是,我不知道如何更改它,以便在更新时,它将更新密码列?我尝试了它,但它不起作用。我认为这不是因为保留字,而是因为如果我使用isnull(密码“”),映射将被抛出。那么我如何重新映射所有内容呢?您是否尝试过
NULLIF
而不是我发现的
ISNULL
dataAdapter = new SqlDataAdapter("Select username, isnull([password],'') from Credentials", connectionString);