Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据表不接受在网格视图中为更新数据库所做的更改_C#_Winforms_Gridview_Datatable_Windows Applications - Fatal编程技术网

C# 数据表不接受在网格视图中为更新数据库所做的更改

C# 数据表不接受在网格视图中为更新数据库所做的更改,c#,winforms,gridview,datatable,windows-applications,C#,Winforms,Gridview,Datatable,Windows Applications,我有下面的代码,我正试图从Windows应用程序中的c#网格视图更改中更新数据库 代码未更新SQL Server数据库。。。我不确定问题到底发生在哪里。一切似乎都很好 或者有没有办法再次使用“更新查询语句”来更新数据库表?重点是如何为数据网格视图中的任何值更改编写udate语句 我猜想绑定和select命令语句可能有问题 有人能给我指出解决这个问题的正确方向吗 public partial class KnowledgeBaseForm : Form { private SqlDataA

我有下面的代码,我正试图从Windows应用程序中的c#网格视图更改中更新数据库

代码未更新SQL Server数据库。。。我不确定问题到底发生在哪里。一切似乎都很好

或者有没有办法再次使用“更新查询语句”来更新数据库表?重点是如何为数据网格视图中的任何值更改编写udate语句

我猜想绑定和select命令语句可能有问题

有人能给我指出解决这个问题的正确方向吗

public partial class KnowledgeBaseForm : Form
{
    private SqlDataAdapter SDA = new SqlDataAdapter();
    private DataTable DT = new DataTable();

    private void button_retrievekb_Click(object sender, EventArgs e)
    {
        try
        {
            con.Open();
            SqlDataAdapter SDA = new SqlDataAdapter(@"SELECT * From Table1", con);

            SDA.Fill(DT);

            bindingsource.DataSource = DT;
            dataGridView.DataSource = bindingsource;

            if (DT.Rows.Count > 0)
            {
                dataGridView.Columns[0].DefaultCellStyle.ForeColor = Color.Gray;
                dataGridView.Columns[0].ReadOnly = true;
            }
            else
            {
                MessageBox.Show("No Knowledge Base Rules Found");
             }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error : " + ex.Message);
        }
        finally
        {
            con.Close();
        }
    }

    private void button_update_Click(object sender, EventArgs e)
    {
        if (MessageBox.Show("Do you really want to Update these values?", "Confirm Update", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            //binding the datasource with the changes made in the gridview
            bindingsource.DataSource = dataGridView.DataSource;

            scb = new SqlCommandBuilder(SDA);                 
            SDA.Update((DataTable) bindingsource.DataSource);

            MessageBox.Show("Updates successfully submitted to CoSD");
        }
    }
}

不确定是否有更多错误,但首先删除“DT.AcceptChanges();”,它将接受所有更改,因此这些更改将变为“未更改”,然后SDA.Update将不做任何操作,因为它“看不到”任何更改。@Gusman2:感谢您的评论。。。我没有显示任何错误。。。但是数据库没有升级。。。请现在查看已编辑的代码。。。我在运行时在datagrid视图中进行更改,并学习了一些使用此方法的链接。。。。现在我删除了它,但它仍然没有得到更新…在单击事件中,只尝试以下代码:if(MessageBox.Show(“您真的想更新这些值吗?”,“确认更新”,MessageBoxButtons.YesNo)=DialogResult.Yes){dataAdapter.Update((DataTable)bindingSource1.DataSource);}