【问题标题】:Update the sqlite from datagrid using c#使用c#从datagrid更新sqlite
【发布时间】:2023-03-23 05:48:02
【问题描述】:

我能够打开数据网格连接,现在在打开后的数据网格中我想通过文本框更新特定值。但是我应该如何使用网格进行更新。

下面是代码

    private void button3_Click(object sender, EventArgs e)
    {
        SQLiteConnection connection4 = new SQLiteConnection(@"Data Source = C:\foo.sqlite;Version =3");
        connection4.Open();
        string sql2 = "Update Table set language1= '" + textBoxUpdate1.Text + "' where language1 = '" + textBox_Search.Text + "'";
        SQLiteDataAdapter connect4 = new SQLiteDataAdapter(sql2, connection4);
        DataSet ds4 = new DataSet();
        connect4.Fill(ds4);
        dataGridView.DataSource = ds4.Tables[0];
    }

从图像中我想说我想更新语言 2,所以我将在第二个文本框中输入我将在更新语句中设置的位置,但“位置”我想选择用户在数据网格,下面是数据网格选择所在的更新表,在那个地方我想要选择数据网格

喜欢

    string sql2 = "Update Table set language1= '" + textBoxUpdate1.Text + "' where language1 = '" + DATAGrid Selection + "'"; 

这可能吗?

【问题讨论】:

  • 别忘了处理掉你的 SQLiteConnection。建议将此代码包装在 Using

标签: c# winforms datagrid datagridview


【解决方案1】:

DataGridView 公开了您可以检查以提取所选内容的属性。您可以在此MSDN Link 中找到更多信息

【讨论】:

    【解决方案2】:

    运行以下代码以编辑网格中的特定内容。只需在网格上编辑并按更新按钮。形成以下代码,您可以通过对其进行编辑来编辑特定行并按下更新按钮

      private void button3_Click(object sender, EventArgs e)
        {
            DataTable dt = dataGridView.DataSource as DataTable;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i].RowState == DataRowState.Modified)
                {
                    MessageBox.Show(dt.Rows[i][3].ToString());
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 2014-04-11
      • 2022-01-15
      • 1970-01-01
      相关资源
      最近更新 更多