控件上的操作会了,先添加一个项目数据源,再添加两个BUTTON,一个保存,一个取消操作
private void button1_Click(object sender, EventArgs e)
{
adminTableAdapter.Update(dataSet1);
MessageBox.Show("保存成功");
} private void button2_Click(object sender, EventArgs e)
{
dataSet1.RejectChanges();
}希望高手指教这些怎么用代码实现~~~
private void button1_Click(object sender, EventArgs e)
{
adminTableAdapter.Update(dataSet1);
MessageBox.Show("保存成功");
} private void button2_Click(object sender, EventArgs e)
{
dataSet1.RejectChanges();
}希望高手指教这些怎么用代码实现~~~
我一直都这么用,不知道符合你的要求么。
DataGridView1.ValueMember = "Value ";
DataGridView1.DataSource = dt;
{
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;
}