-
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
-
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
>
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks