控件上的操作会了,先添加一个项目数据源,再添加两个BUTTON,一个保存,一个取消操作
private void button1_Click(object sender, EventArgs e)
        {
            adminTableAdapter.Update(dataSet1);
            MessageBox.Show("保存成功");
        }        private void button2_Click(object sender, EventArgs e)
        {
            dataSet1.RejectChanges();
        }希望高手指教这些怎么用代码实现~~~

解决方案 »

  1.   

    没人吗?其实我就想实现一个用datagridview显示所有用户,然后再增加两个BUTTON可以增删改查所有用户
      

  2.   

    这个难道不是在 Button 的 Click 事件上写 SQL 增删语句,然后再重新调用 SQL Select ,绑定数据源,刷新一下么?
    我一直都这么用,不知道符合你的要求么。
      

  3.   

    楼主的意思是这个??DataGridView1.DisplayMember   =   "Display "; 
    DataGridView1.ValueMember   =   "Value "; 
    DataGridView1.DataSource   =   dt; 
      

  4.   

    添加DataGridView的数据源private void InitializeDataGridView()
    {
        try
        {
            // Set up the DataGridView.
            dataGridView1.Dock = DockStyle.Fill;        // Automatically generate the DataGridView columns.
            dataGridView1.AutoGenerateColumns = true;        // Set up the data source.
            bindingSource1.DataSource = GetData("Select * From Products");
            dataGridView1.DataSource = bindingSource1;        // Automatically resize the visible rows.
            dataGridView1.AutoSizeRowsMode =
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;        // Set the DataGridView control's border.
            dataGridView1.BorderStyle = BorderStyle.Fixed3D;        // Put the cells in edit mode when user enters them.
            dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
        }
        catch (SqlException)
        {
            MessageBox.Show("To run this sample replace connection.ConnectionString" +
                " with a valid connection string to a Northwind" +
                " database accessible to your system.", "ERROR",
                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            System.Threading.Thread.CurrentThread.Abort();
        }
    }private static DataTable GetData(string sqlCommand)
    {
        string connectionString = "Integrated Security=SSPI;" +
            "Persist Security Info=False;" +
            "Initial Catalog=Northwind;Data Source=localhost";    SqlConnection northwindConnection = new SqlConnection(connectionString);    SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = command;    DataTable table = new DataTable();
        table.Locale = System.Globalization.CultureInfo.InvariantCulture;
        adapter.Fill(table);    return table;
    }