如何使用SqlCeDataAdapter编辑datagridview?

发布于 2024-08-24 22:14:26 字数 691 浏览 3 评论 0原文

我有一个带有 datagridview 的 frmEdit ,它与此相关:

string sqlqry1 = "select p_Name from Items where p_Id=" + p_Id;
        using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
        }

How to edit cells and save them back to the db?,尝试使用这个:

using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
            a.Update(dt1);
        }

Nothing。

到底还有吗?

I've a frmEdit with datagridview that's bouned to this:

string sqlqry1 = "select p_Name from Items where p_Id=" + p_Id;
        using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
        }

How to edit cells and save them back to the db?, tried using this:

using (SqlCeDataAdapter a = new SqlCeDataAdapter(sqlqry1, conn))
        {
            DataTable dt1 = new DataTable();
            a.Fill(dt1);
            dataGridView1.DataSource = dt1;
            a.Update(dt1);
        }

Nothing.

Is there anyway?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七月上 2024-08-31 22:14:26

找到解决方案:

        SqlCeDataAdapter da;
        SqlCeCommandBuilder cmdBuilder;


        da = new SqlCeDataAdapter("select * from Items", conn);
        cmdBuilder = new SqlCeCommandBuilder(da);
        da.Fill(myDatabaseDataSet, "Items");
        myDatabaseDataSet.Tables["Items"].Rows[0]["p_Name"] = dataGridView1.Rows[0].Cells["p_Name"].Value.ToString();
        da.Update(myDatabaseDataSet, "Items"); 

Found solution:

        SqlCeDataAdapter da;
        SqlCeCommandBuilder cmdBuilder;


        da = new SqlCeDataAdapter("select * from Items", conn);
        cmdBuilder = new SqlCeCommandBuilder(da);
        da.Fill(myDatabaseDataSet, "Items");
        myDatabaseDataSet.Tables["Items"].Rows[0]["p_Name"] = dataGridView1.Rows[0].Cells["p_Name"].Value.ToString();
        da.Update(myDatabaseDataSet, "Items"); 
狠疯拽 2024-08-31 22:14:26
DataTable dT;
BindingSource bS;

using (SqlCeConnection yourConnection = new SqlCeConnection("Data Source=|DataDirectory|\\YourDatabase.sdf"))
{
    dT = new DataTable();
    bS = new BindingSource();    

    string query = "SELECT * FROM table01";
    SqlCeDataAdapter dA = new SqlCeDataAdapter(query, yourConnection);
    SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(dA);
    dA.Fill(dT);

    bS.DataSource = dT;
    dgv01.DataSource = bS;
}

由于该页面在谷歌上的排名,因此用一个工作示例来复活它。

DataTable dT;
BindingSource bS;

using (SqlCeConnection yourConnection = new SqlCeConnection("Data Source=|DataDirectory|\\YourDatabase.sdf"))
{
    dT = new DataTable();
    bS = new BindingSource();    

    string query = "SELECT * FROM table01";
    SqlCeDataAdapter dA = new SqlCeDataAdapter(query, yourConnection);
    SqlCeCommandBuilder cBuilder = new SqlCeCommandBuilder(dA);
    dA.Fill(dT);

    bS.DataSource = dT;
    dgv01.DataSource = bS;
}

Resurrecting this with a working example because of this pages rank on google.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文