表是一张表,窗口有两个buttn 一个是update 一个是insert, 在datagridview 中修改数据点update后更新 ,增加行后点击insert 插入
请给出详细代码,第一个给出代码调试能用这给满分.

解决方案 »

  1.   

    heh呵呵 网上一大堆的你还是问GOOLGLE最好了  
    上面都有的 自己搜下了  多动动手了
      

  2.   

    分有什么用?
    你直接copy代码有什么用?
    ....最简单的对一张表的维护,insert,update,delete.....
      

  3.   


    string strSqlDel = "delete from 表 where 条件 ";
    clsSql.Ex(strSqlDel);            for (int i = 0; i < this.ucDataGridView1.Rows.Count - 1; i++)
                {
                    string 编号, 名称, 类别;                if (this.ucDataGridView1.Rows[i].Cells[0].Value == null)
                    {
                        编号 = "";
                    }
                    else
                    {
                        编号 = this.ucDataGridView1.Rows[i].Cells[0].Value.ToString();
                    }                if (this.ucDataGridView1.Rows[i].Cells[1].Value == null)
                    {
                        名称 = "";
                    }
                    else
                    {
                        名称 = this.ucDataGridView1.Rows[i].Cells[1].Value.ToString();
                    }                if (this.ucDataGridView1.Rows[i].Cells[2].Value == null)
                    {
                        类别 = "";
                    }
                    else
                    {
                        类别 = this.ucDataGridView1.Rows[i].Cells[2].Value.ToString();
                    }                if (编号 == "" || 名称 == "")
                    {
                        continue;
                    }
                    string strSql = "insert into 表(大类编号,编号,名称,类别) " +
                                    "values( " +
                                    "'" + no + "','" + 编号 + "','" + 名称 + "','" + 类别 +
                                    "')";                    clsSql.Ex(strSql);            }
    先删除,再遍历插入,这样的话,2个按钮直接一个按钮就可以了