【问题标题】:C# Datagridview rows not updated by insert to databaseC# Datagridview 行未通过插入数据库更新
【发布时间】:2014-07-22 17:53:44
【问题描述】:

我在 C# 中有一个本地数据库,我通过这个命令返回它的内容:

    public DataTable getVillages()
    {
        try
        {
            string strCommand = "SELECT * FROM village";
            DataTable dt = new DataTable();
            SqlCeDataAdapter da = new SqlCeDataAdapter(strCommand, conn);
            da.Fill(dt);
            return dt;
        }
        catch (SqlCeException e)
        {
            MessageBox.Show(e.Source + "\n" + e.Message + "\n" + e.StackTrace);

            return null;
        }
    }

另一方面,我得到这个数据表并将其分配给我的 datagridview :

dataGridView.DataSource = villageData.getVillages();

但我的 dataGridView RowsCount 为 0,并且其行未随数据库内容更新。但是我在运行时看到 dataGridView 中插入的行,但它的行数是 0。

【问题讨论】:

    标签: c# sql-server-ce


    【解决方案1】:

    您尝试更新 DataGrid?

    dataGridView.DataBind();
    

    【讨论】:

    • 我没有这种方法
    • 该方法适用于 ASP.Net DataGrid,而不是 winforms DataGridView
    猜你喜欢
    • 2016-02-12
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多