有3个需要循环更新的字段分别是  jd1 jd2 jd3希望在vs2005的gridview中循环更新
我的思路非常混乱.希望强人给全部代码.(要VB的)我的混乱代码如下.
 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim constr As String = "data source=10.61.224.1;user id=sa;password=sa;database=ZKJRL ;Asynchronous Processing=true"
        Dim sqlstr As String = "SELECT * FROM [HTCPSGTZD_JRLJDQKB2]  "
        Dim objconn As New System.Data.SqlClient.SqlConnection(constr)
        Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter(sqlstr, objconn)
        Dim objdataset As New System.Data.DataSet        objAdapter.Fill(objdataset, "HTCPSGTZD_JRLJDQKB2")
        Dim textbox13 As String = ""        Dim i As Integer
        Dim jd1 As String = Trim(textbox13) 'GridView1.Rows(i).FindControl("textbox13")
        For i = 0 To objdataset.Tables("jd1").Rows.Count() - 1            objdataset.Tables("HTCPSGTZD_JRLJDQKB2").Rows(i)("jd1") = jd1            Dim dd As New System.Data.SqlClient.SqlCommandBuilder(objAdapter)
            objAdapter.Update(objdataset, "HTCPSGTZD_JRLJDQKB2")
        Next
        objconn.Close()
    End Sub

解决方案 »

  1.   

    没看懂要干嘛.for(int i = 0;i<objdataset.tables[0].Rows.Count();i++)
    {
      objdataset.Tables[0].Rows[i]["jd1"] = jd1;
      ????
    }
      

  2.   

    for(int   i   =   0;i <objdataset.tables[0].Rows.Count();i++) 

        objdataset.Tables[0].Rows[i]["jd1"]   =   jd1; 
        objdataset.Tables[0].Rows[i]["jd2"]   =   jd2;
        objdataset.Tables[0].Rows[i]["jd3"]   =   jd3;
    }
    大概就是这样了!
      

  3.   

    在gridview外面加一个按钮.目的是修改所有的记录后点这个按钮全部保存,这样就不用一条一条的保存了.
    不是要用循环语句吗?
    我不会写.而且怎么写更新我也不会.反正就是要VB的详细代码.140分相送.
      

  4.   


    System.Data.SqlClient.SqlCommandBuilder cb = new System.Data.SqlClient.SqlCommandBuilder(objAdapter);
    objAdapter.Update(objdataset);
      

  5.   

    For Each gdr As GridViewRow In GridView1.Rows     dim mytxt as textbox = ctype(gdr.findcontrol("textbox13"),textbox)
      
          mytxt.text = "xxxxxx"Nextps:gridview按業顯示,例:有3頁,你就必須 點3次按鈕去update gridview
      

  6.   

    别光写for的呀,
    诸如   Dim   sqlstr   As   String   =   "SELECT   *   FROM   [HTCPSGTZD_JRLJDQKB2]     " 
                    Dim   objconn   As   New   System.Data.SqlClient.SqlConnection(constr) 
    这类的声明怎么写也来点详细的,我很苯的,不会举一反三.
      

  7.   

    lz你是根本偷懒,一般只能给你一个思路,你自己要知道怎么调试怎么修改代码的;理论上:你循环每个行,然后获取修改后的值,for里面应该有3个赋值语句把;最后更新;
    vb不会
      

  8.   

    用循环更新就直接写更新查询语句执行了,
    用批量更新:先对datatable更新完了再objAdapter.Update(objdataset,   "HTCPSGTZD_JRLJDQKB2")更新到数据库
      

  9.   

     不能張口就要code.關鍵自己要去理解為什麼這樣寫...
    別人只能給你一個思路而已..
     
      

  10.   

       Dim constr As String = "data source=10.61.224.1;user id=sa;password=sa;database=ZKJRL ;Asynchronous Processing=true"
            Dim str As String
            Dim StrSource As String
            Dim Rs As ADODB.Recordset
            Dim I As Long
            str = TextBox1.Text
            Rs = New ADODB.Recordset
            StrSource = "select * from HTCPSGTZD_JRLJDQKB2 where  jdrq = '" & str & "' "
            '=====================   
            '注意打开方式为,静态、成批   
            Rs.Open(StrSource, constr, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
            '=====================   
            If Rs.RecordCount > 0 Then
                Rs.MoveFirst()
                Do While Rs.EOF = False
                    For I = 0 To Rs.Fields.Count - 1
                        If Not System.Data.DataRow.IsNull(Rs.Fields(I).Value) Then                           '判断是否为NULL   
                            If TypeName(Rs.Fields(I).Value) = "String" Then     '判断字段是否为String型   
                                Rs.Fields(I).Value = Trim(Rs.Fields(I).Value)
                            End If
                        End If
                    Next I
                    Rs.MoveNext()                                                                                     '移向下一条记录   
                Loop
                Rs.UpdateBatch(ADODB.AffectEnum.adAffectAllChapters)                                         '一次性成批修改记录集   
            End If又寻思一下午,这个代码居然提示我"多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。"怎么回事?