用detSet的UPDATA,会看动提交改变后的数据

解决方案 »

  1.   

    应该是可以的,你在点提交按钮后遍历datagrid的行与列,将用户更改的数据保存到dataset再调用dataadapter的update方法
      

  2.   

    有人能提供遍历的方法的方法,和如何把dataset用调用dataadapter的updata方法入库吗?
      

  3.   

    不见意再用dataset,直接sql到数据库 private void Button1_Click(object sender, System.EventArgs e)
    { for(int i=0;i<DataGrid1.Items.Count;i++)
    {
    TextBox tb=(TextBox)DataGrid1.Items[i].Cells[4].FindControl("textboxchengji");
    Label lb=(Label)DataGrid1.Items[i].Cells[4].FindControl("labelxuehao"); string sql="UPDATE "+tab+" SET  chengji='"+tb.Text+"' WHERE xuehao= "+lb.Text;
    DbExec(sql);
    }
    }
    public bool DbExec(string sql)
    {
    DbOpen();
    try
    {
    infocomm=new OleDbCommand(sql,linkDb);
    infocomm.ExecuteNonQuery();
    infocomm.Dispose();
    linkDb.Close();
    return true;
    }
    catch(OleDbException e)
    {
    linkDb.Close();
    getErr+="["+e.ErrorCode.ToString()+"]"+e.Message.ToString();
    return false;
    }
    }
      

  4.   

    中间有什么地方不对请自己检查:
    Label lb=(Label)DataGrid1.Items[i].Cells[0].FindControl("labelxuehao");
      

  5.   

    帮我看看我写的错在那里了,我用这个程序后添到成绩里的值没有写到库里,请各位哥哥一定要帮忙,小妹谢过了!!
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim myconn As New SqlConnection("Server = localhost; uid=sa;pwd=lcdgn;database=pygl")
            Dim ds As New DataSet()
            Dim sqld As SqlDataAdapter
            Dim str As String
            Dim obj As TextBox
            Dim dtable As DataTable
            Dim drows As DataRowCollection
            Dim drow As DataRow
            str = "select pyjh.xuehao,xsda.xingming,pyjh.kcxz,pyjh.khfs,pyjh.chengji from pyjh,xsda,kc where pyjh.xuehao=xsda.xuehao and kc.kcbh=pyjh.kcbh and kc.kcmc='" + TextBoxkcmc.Text + "' and pyjh.kksj='" + TextBoxkksj.Text + "'"
            myconn.Open()
            sqld = New SqlDataAdapter(str, myconn)
            Dim objc As New SqlCommandBuilder(sqld)
            sqld.Fill(ds, "mytable")
            dtable = ds.Tables("mytable")
            drows = dtable.Rows
            Dim introw As Integer
            dtable.AcceptChanges()
            sqld.Update(ds, "mytable")
            For introw = 0 To ds.Tables("mytable").Rows.Count - 1
                drow = drows(introw)
                obj = DataGrid1.Items(introw).Cells(4).FindControl("textboxchengji")
                drow(4) = obj.Text
            Next
            myconn.Close()
            bind()
        End Sub