C#Gridview-聚焦并更改数据库的特定值

时间:2019-03-20 14:22:42

标签: c# sql

我已经以C#格式构建了一个gridview,它使我能够以单一格式在数据库中进行编辑。但是,我希望它以其他方式运行:

  • 当我双击一行时,它仅打开特定的行,并且对应的列以单一形式显示。
  • 打开后,我立即编辑该行。它保存在数据库中。

我想尝试做的是:

SELECT ColumnName1, ColumnName2 
FROM TableName 
WHERE ColumnName1 = @ParameterName

其中参数名称是ID,在该ID中我双击另一种形式。我目前为止的工作:

using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;




namespace TestInventory
{


  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'prismaWinPosDataSet.Inventory' table. You can move, or remove it, as needed.
            this.inventoryTableAdapter.Fill(this.prismaWinPosDataSet.Inventory);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {        
            //      inventoryBindingSource.Update(prismaWinPosDataSet,"Inventory");
            gridView1.PostEditor(); //save the cell value to a data source 
            gridView1.UpdateCurrentRow(); //update the row and raise the RowUpdated event 
                                          //   dbContext

        inventoryTableAdapter.Update(this.prismaWinPosDataSet.Inventory);

    }

//单元格验证规则

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
   //     context.SubmitChanges();
    }

    private void simpleButton3_Click(object sender, EventArgs e)
    {
        inventoryBindingSource.AddNew();
    }


    private void simpleButton4_Click(object sender, EventArgs e)
    {
       if (XtraMessageBox.Show("Delete?", "Message",MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes);
        inventoryBindingSource.RemoveCurrent();
    }

    private void gridView1_DoubleClick(object sender, EventArgs e)
    {
     //   int invID = gridView1.GetRow;

        Form2 frm = new Form2(2);
        frm.ShowDialog();
    }

    private void fillByToolStripButton_Click(object sender, EventArgs e)
    {


    }
}
}

单个表单正常工作,正在数据库中更新。single Form 消息框“确定”是因为我尚未完成以第二种形式将其连接到查询的过程。

0 个答案:

没有答案