关与C#数据修改与删除的实现

来源:百度知道 编辑:UC知道 时间:2024/06/28 03:28:15
我现在用到了3个button组件 一个命名为添加 一个命名为删除 一个为保存
还有个DataGridView组件(该组件已连到数据库 并且有数据了)
现在我想对DataGridView里的数据进行如button命名的意思去操作 应该怎么做
问下可以用DataSet实现吗?

DataBasePath q = new DataBasePath();//实例化用户自定义类DataBasePath
SqlConnection conn = new SqlConnection(q.GetPath());
conn.Open();
DataSet ds = new DataSet();
// SqlDataAdapter mycmd = new SqlDataAdapter("delete * from 用户信息表 where User_id ='" + this.dGV_user[0, this.dGV_user.CurrentCell.RowIndex].Value.ToString().Trim() + "' ", conn);
string sqlstring="delete from 用户信息表 where User_id ='" + this.dGV_user[0, this.dGV_user.CurrentCell.RowIndex].Value.ToString().Trim()+"'" ;
SqlCommand mycmd = new SqlCommand(sqlstring, conn);
int check1= mycmd.ExecuteNonQuery();
if (check1 == 1)
{
this.dGV_user.Rows.RemoveAt(this.dGV_user.CurrentCell.RowIndex);//从datagridview中删除选中元素所在的行