Selecting fields in an Access DB

Selecting fields in an Access DB

Post by Mik » Thu, 09 Jan 2003 06:54:43



I am writing some VB code that grabs data from an external source.  I
parse the data and then need to update or insert the database.  The
code is this:

Dim sql as string
sql= "select Router, Routing_Protocol, Network, Mask, Next_Hop,
Distance From Table_Routes Where (Router='" & Router & "' and Network
= '" & Network & "'"

How do I issue this command to the database and find out if the row
esists?

Based on if it exists I need to do an UPDATE or an INSERT to the
database.

Thanks.
Mike

 
 
 

Selecting fields in an Access DB

Post by Clothild » Thu, 09 Jan 2003 08:08:35


Set MyRecordset = MyDB.Openrecordset(sql)

If MyRecordset.eof then
    INSERT ...
else
    UPDATE ...
end if


Quote:> I am writing some VB code that grabs data from an external source.  I
> parse the data and then need to update or insert the database.  The
> code is this:

> Dim sql as string
> sql= "select Router, Routing_Protocol, Network, Mask, Next_Hop,
> Distance From Table_Routes Where (Router='" & Router & "' and Network
> = '" & Network & "'"

> How do I issue this command to the database and find out if the row
> esists?

> Based on if it exists I need to do an UPDATE or an INSERT to the
> database.

> Thanks.
> Mike


 
 
 

Selecting fields in an Access DB

Post by Mik » Thu, 09 Jan 2003 23:57:25


Do I need to delclare MyRecordset or MyDB???

If so how do I do that?

Mike


> Set MyRecordset = MyDB.Openrecordset(sql)

> If MyRecordset.eof then
>     INSERT ...
> else
>     UPDATE ...
> end if



> > I am writing some VB code that grabs data from an external source.  I
> > parse the data and then need to update or insert the database.  The
> > code is this:

> > Dim sql as string
> > sql= "select Router, Routing_Protocol, Network, Mask, Next_Hop,
> > Distance From Table_Routes Where (Router='" & Router & "' and Network
> > = '" & Network & "'"

> > How do I issue this command to the database and find out if the row
> > esists?

> > Based on if it exists I need to do an UPDATE or an INSERT to the
> > database.

> > Thanks.
> > Mike

 
 
 

Selecting fields in an Access DB

Post by Clothild » Fri, 10 Jan 2003 06:20:17


This is not a trivial question. If you need to ask how to declare the DB,
you need to go back and read quite a lot about working with databases.

1. Choose between DAO and ADO as your data system.
2. Add whichever you choose to your project's references.
3. Declare and create your data objects


> Do I need to delclare MyRecordset or MyDB???

> If so how do I do that?

> Mike




> > Set MyRecordset = MyDB.Openrecordset(sql)

> > If MyRecordset.eof then
> >     INSERT ...
> > else
> >     UPDATE ...
> > end if



> > > I am writing some VB code that grabs data from an external source.  I
> > > parse the data and then need to update or insert the database.  The
> > > code is this:

> > > Dim sql as string
> > > sql= "select Router, Routing_Protocol, Network, Mask, Next_Hop,
> > > Distance From Table_Routes Where (Router='" & Router & "' and Network
> > > = '" & Network & "'"

> > > How do I issue this command to the database and find out if the row
> > > esists?

> > > Based on if it exists I need to do an UPDATE or an INSERT to the
> > > database.

> > > Thanks.
> > > Mike

 
 
 

1. Selecting items in a DB-list and passing fields from selected rec to a control

I am trying to use VB with an external DB using the DATA control with a
control with a DB-list and a series of textboxes by selecting items in a
DBlist and passing a field from the selected record to a textbox. I want
to navigate through the recs using the DBLIST, not the data control. In
the DBLIST_CLICK event, I do a MOVEFIRST. The event seems to kick off
twice, giving me a "Method not valid for this control" error. I would
have thought I could have exec'd MOVEFIRST a thousand times if I wanted,
since it should only position me to TOF for the recordset.

Has anyone else had problems using a DBLIST? If so, how dis you oversome
your probs? Can you offer advice on mine?

TIA,
Mark Jordan
City of NN

2. Promotable lock types

3. Adding Field to Access db - need to make indexed property of field No Duplicates

4. importing picture

5. VB30: Accessing OLE-field in ACCESS-DB via OLE-VBX

6. W4GL to OR3.5 pb

7. how to copy a db to another db table by table and field by field

8. Select from ORACLE table with NUMERIC field via OLE DB

9. Using Text Field in DB to Store Select Queries

10. Exporting selected records to new DB (access and VB3)

11. SELECT @@IDENTIFY against Access DB

12. Multi 'Select' in Access DB