111,120
社区成员
发帖
与我相关
我的任务
分享
private void DeleteSelectedButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show("删除所选记录,你确定吗?", "确认删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
return;
for (int i = HistoryView.Rows.Count - 1; i >= 0; i--)
{
DataGridViewRow row = HistoryView.Rows[i];
if (Convert.ToBoolean(row.Cells[0].Value) == true)
{
HistoryView.Rows.RemoveAt(i);
}
}
maOp.manDB.SubmitChanges();
}
HistoryView.DataSource = maOp.GetOldHistory(DateTime.Now) ;
BindingSource bs = new BindingSource();
BindingList<Man_Log> bl = new BindingList<Man_Log>(maOp.GetOldHistory(DateTime.Now));
bl.AllowRemove = true;
HistoryView.ReadOnly = false;
bs.DataSource = bl;
HistoryView.DataSource = bs;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataTable dt = new DataTable ();
private OdbcDataAdapter da = new OdbcDataAdapter();
private void Form1_Load_1(object sender, EventArgs e)
{
OdbcConnection cn = new OdbcConnection("driver={IBM DB2 ODBC DRIVER};Database=SDDT;hostname=223.1.1.19;port=50000; protocol=TCPIP;uid=LLL;pwd=BCL987; CurrentSchema=SDDT;");
OdbcCommand com = new OdbcCommand("select * from MODEL", cn);
da =new OdbcDataAdapter (com );
DataTable dt = new DataTable();
dt .Locale = System .Globalization .CultureInfo .InvariantCulture ;
da.Fill(dt);
this.dataGridView1.DataSource = dt;
}
private void getupdate()
{
dt = dataGridView1.DataSource as DataTable;//把DataGridView绑定的数据源转换成DataTable
OdbcCommandBuilder cb = new OdbcCommandBuilder(da);
//将数据放到datatable 中 datagridview 的数据源 是datatable
//修改datagridview
//更新
da.Update(dt);
}
private void button1_Click_1(object sender, EventArgs e)
{
this.getupdate();
MessageBox.Show("更新成功");
}
private void button2_Click(object sender, EventArgs e)
{
OdbcConnection con = Program.createConnection();
con.Open();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string querysql = "select * from MODEL";
OdbcDataAdapter da = new OdbcDataAdapter(querysql, con);
da.Fill(ds, "tab");
dt = ds.Tables[0];
this.dataGridView1.DataSource = dt;
con.Close();
}
private void button3_Click(object sender, EventArgs e)
{
int row = dataGridView1.SelectedRows.Count;
if (MessageBox.Show("确认删除选中的" + row.ToString() + "条记录吗?", "请确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
while (row > 0)
{
((DataRowView)dataGridView1.SelectedRows[0].DataBoundItem).Row.Delete();
row = row - 1;
}
this.getupdate();
MessageBox.Show("删除成功");
}
}