datagridview 数据处理方法 修改 删除 添加 下拉类表 弹出窗口
DataSet ds = dataoperate.getDs(strSql, "user_tb1");
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns[0].ReadOnly = true; //列不可编写
}
private void button8_Click(object sender, EventArgs e)
{
//显示到最后一页
DataOperate dataoperate = new DataOperate();
pagenumber = pagesum;
button7_Click(sender, e);
//添加行数据
((DataTable)dataGridView1.DataSource).Rows.Add(1,"","000000");//就这一句就可以了,兄弟!也就是说dataGridView1是不能直接添加行的,只能在他的数据源里添,他会自动绑定
}
private void button9_Click(object sender, EventArgs e)
{
int
myid=int.Parse(dataGridView1.Rows[selectindex].Cells[0].Value.ToString());
string mysql = "delete from user_tb1 where ID=" + myid.ToString();
DataOperate dataoperate = new DataOperate();
dataoperate.getCom(mysql);
MessageBox.Show("删除数据成功");
//获取总页码 SELECT Count(id) AS number1 FROM user_tb1;
mysql = "SELECT Count(id) AS number1 FROM user_tb1 ";
DataSet ds = dataoperate.getDs(mysql, "user_tb1");
int indexsum = int.Parse(ds.Tables[0].Rows[0][0].ToString());
if (indexsum % pagesize == 0)
label5.Text = (indexsum / pagesize).ToString();
else