First Recordset.AddNew Doesn't Appear in Grid

First Recordset.AddNew Doesn't Appear in Grid

Post by Phil Gale » Fri, 07 Jan 2000 04:00:00



I'm using VB6 Enterprise.  I have a DataGrid Connected to an adodc that I'm
calling adcEvents, which is in turn connected to an Access 97 database table
called Events.  I'm just working with one table.

First I empty the table using

    Dim dbEvents as Database
    Set dbEvents = Workspaces(0).OpenDatabase("LeavTrak.mdb")
    dbEvents.Execute "DELETE * FROM Events"
    adcEvents.Refresh

which only sometimes results in the data being emptied from the grid.

Then I start adding data to the table using

    adcEvents.Recordset.AddNew
    adcEvents.Recordset!Code = txtEventCode.Text
    adcEvents.Recordset!Date = Calendar1.Value
    adcEvents.Recordset!Hours = txtHours.Text
    adcEvents.Recordset.Update
    adcEvents.Refresh

but, strangely, the first row added never shows in the grid.  Only starting
with the second AddNew does the data start appearing in the grid.  Why is
this?

 
 
 

First Recordset.AddNew Doesn't Appear in Grid

Post by Phil Gale » Sat, 08 Jan 2000 04:00:00


I found the answer:  After Updating the Recordset, Requery the Recordset and
then Refresh the DataGrid.  So, Requery of the Recordset replaces Refresh of
the data control.

Phil Galey
------------------------------------------------------------------------


Quote:> I'm using VB6 Enterprise.  I have a DataGrid Connected to an adodc that
I'm
> calling adcEvents, which is in turn connected to an Access 97 database
table
> called Events.  I'm just working with one table.

> First I empty the table using

>     Dim dbEvents as Database
>     Set dbEvents = Workspaces(0).OpenDatabase("LeavTrak.mdb")
>     dbEvents.Execute "DELETE * FROM Events"
>     adcEvents.Refresh

> which only sometimes results in the data being emptied from the grid.

> Then I start adding data to the table using

>     adcEvents.Recordset.AddNew
>     adcEvents.Recordset!Code = txtEventCode.Text
>     adcEvents.Recordset!Date = Calendar1.Value
>     adcEvents.Recordset!Hours = txtHours.Text
>     adcEvents.Recordset.Update
>     adcEvents.Refresh

> but, strangely, the first row added never shows in the grid.  Only
starting
> with the second AddNew does the data start appearing in the grid.  Why is
> this?


 
 
 

1. AddNew with ADO Recordset doesn't seem to work

Hi,
Can Anyone help me?  I seem to have been going round in Circles for days!!

I'm Trying to use an ADO Recordset with no Recordsource to Hold Data in an
ASP page (Which will later hold the data for the session).  Specifically,
this data is comming from an Index Server Recordset, which I iterate through
and add certain records into the new recordset.  However, When I try to
display the contents of the recordset, all the added data is blank!  Any
Ideas?  The code is below.

Thanks

<html>
<head>

    <TITLE>Search Form</TITLE>

</head>
<body>
<%
' *********  Subs used to fill Category1 and Category2 Recordsets *********

Set Q = Server.CreateObject("Ixsso.Query")

Q.DefineColumn "Category1 (DBTYPE_WSTR) =
d5cdd505-2e9c-101b-9397-08002b2cf9ae documenttype"

'Q.Columns = "Category1, Category2"
Q.Columns = "Category1, Path"
'Q.SortBy = "Category1[a],Category2[a]"
Q.SortBy = "Category1[a]"
Q.MaxRecords = 300
Set RSCat1 = Q.CreateRecordset("nonsequential")

Set rst = Server.CreateObject("ADODB.Recordset")
rst.fields.Append "Category1", adChar, 100
rst.fields.refresh
rst.Open

RSCat1.MoveFirst
Cat1 = RSCat1("Category1").value
RSCat1.MoveNext

rst.AddNew "Category1",Cstr(Cat1)
rst.Fields("Category1").Value = Cstr(Cat1)
rst.update
%> **<%response.write(Cat1)%>**<BR><%
%>**<% response.write(rst.Fields("Category1").Value) %>**<BR><%

do until RSCat1.Eof
 if Cat1 = RSCat1("Category1").value then
  RSCat1.MoveNext
 else
  if not RSCat1("Category1").value = "" then
  Cat1 = RSCat1("Category1").value
  %> **<%response.write(Cat1)%>**<BR><%
  rst.AddNew
  rst.Fields("Category1").Value = Cat1
  rst.update
 %>**<% response.write(rst.Fields("Category1").Value) %>**<BR><%
  end if
  RSCat1.MoveNext
 end if
loop

%><BR><BR><BR><%
rst.MoveFirst
do until rst.Eof
 if rst.Fields("Category1").Value = "" then
 %>Blank<BR><%
 else
 %>**<% response.write(rst.Fields("Category1").Value) %>**<BR><%
 end if
 rst.MoveNext
loop
rst.Close

%>
</body>

2. discontinued support for sql7?

3. Addnew Doesn't Addnew!

4. Partial Search

5. Database Doesn't Appear in Enterprise Manager

6. Error on running DTS

7. Raiserror message from Trigger doesn't appear in Access 2000 form

8. Giant database - will it work

9. Indexed view doesn't appear to be using index on queries

10. Scheduled task doesn't appear to finish

11. SQL Server 7.0 doesn't appear backward compatible

12. Mail profile works but doesn't appear !

13. Server Doesn't Appear in ODBC Panel?