How to update data in Datagrid


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How to update data in Datagrid

  1. #1
    Lucie Brochu Guest

    How to update data in Datagrid


    I populate my DataGrid with a reference ADO and SQL-Server.
    This code update only the visible part of my datagrid. So if the user fill
    the last row and then click on the Update Button, nothing happen!!!

    Anyone have an idea?
    This is my code:

    Dim intCtr As Integer
    Dim strSql As String
    Dim cmdVisiteur As ADODB.Command
    Set cmdVisiteur = New ADODB.Command
    cmdVisiteur.ActiveConnection = CnConnection
    cmdVisiteur.CommandType = adCmdText
    With dgProspection
    For intCtr = 0 To .ApproxCount - 1
    On Error GoTo ErrHandler
    .Row = intCtr
    If .Columns(3).Text <> "" Then
    strSql = "INSERT INTO visiteursite (dnsipvisiteur,
    nomvisiteur, destyporg, nompays," & _
    "nomprovince) SELECT DnsIp, NomVisiteur, TypeOrg, NomPays,
    NomProvince" & _
    " FROM " & strVisiteurSite & " WHERE dnsip = " & "'"
    & Trim(.Columns(0).Text) & "'"
    cmdVisiteur.CommandText = strSql
    cmdVisiteur.Execute
    End If
    Next
    End With
    Adodc1.Refresh
    frmResolution.Caption = "Résolution. (" & Adodc1.Recordset.AbsolutePosition
    & "/" & Adodc1.Recordset.RecordCount & ")"
    ErrHandler:
    MsgBox Err.Description


  2. #2
    Tonny H Guest

    Re: How to update data in Datagrid


    Lucie,

    Since you are using ADO Data Control, I would probably have a button called
    "ADD NEW" then what it does it Adodc1.addnew
    then after user enter the data then press a button "UPDATE" Adodc1.update

    -t-

    "Lucie Brochu" <ghislain@prospection.qc.ca> wrote:
    >
    >I populate my DataGrid with a reference ADO and SQL-Server.
    >This code update only the visible part of my datagrid. So if the user fill
    >the last row and then click on the Update Button, nothing happen!!!
    >
    >Anyone have an idea?
    >This is my code:
    >
    > Dim intCtr As Integer
    > Dim strSql As String
    > Dim cmdVisiteur As ADODB.Command
    > Set cmdVisiteur = New ADODB.Command
    > cmdVisiteur.ActiveConnection = CnConnection
    > cmdVisiteur.CommandType = adCmdText
    > With dgProspection
    > For intCtr = 0 To .ApproxCount - 1
    > On Error GoTo ErrHandler
    > .Row = intCtr
    > If .Columns(3).Text <> "" Then
    > strSql = "INSERT INTO visiteursite (dnsipvisiteur,
    >nomvisiteur, destyporg, nompays," & _
    > "nomprovince) SELECT DnsIp, NomVisiteur, TypeOrg, NomPays,
    >NomProvince" & _
    > " FROM " & strVisiteurSite & " WHERE dnsip = " & "'"
    >& Trim(.Columns(0).Text) & "'"
    > cmdVisiteur.CommandText = strSql
    > cmdVisiteur.Execute
    > End If
    > Next
    > End With
    > Adodc1.Refresh
    > frmResolution.Caption = "Résolution. (" & Adodc1.Recordset.AbsolutePosition
    >& "/" & Adodc1.Recordset.RecordCount & ")"
    > ErrHandler:
    > MsgBox Err.Description
    >



  3. #3
    Lim Wing Hoe Guest

    Re: How to update data in Datagrid

    Lucie,
    I am not very sure what you want or expect to happens when the user click on
    the Update button.

    If your problem is nothing is saved to the database:

    You may want to look at the datagrid's properties. If AllowAddNew property
    is false, try set it to true. Also, set the AllowUpdate property to true
    also.

    If your problem is after the data is saved to the database and you want a
    prompt or a message box to tell the user the record is entered, try the
    code:

    Private Sub dgProspection_AfterInsert()
    adodc1.Refresh
    frmResolution.Caption = "Résolution. (" &
    Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount & ")"
    End Sub

    Hope this helps. Please do post a reply about the result of the code.

    Thanks..
    --



    Best Regards,
    Wing Hoe
    ---------------------------------------------------------------
    Email1: winghoe@yahoo.com
    Email2: winghoe@hotmail.com
    ICQ no: 2213281
    ---------------------------------------------------------------


    Lucie Brochu <ghislain@prospection.qc.ca> wrote in message
    news:391c231f$1@news.devx.com...
    >
    > I populate my DataGrid with a reference ADO and SQL-Server.
    > This code update only the visible part of my datagrid. So if the user fill
    > the last row and then click on the Update Button, nothing happen!!!
    >
    > Anyone have an idea?





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center