Board index » delphi » Inserting new records with LEFT JOIN query?

Inserting new records with LEFT JOIN query?

All,

Maybe someone can help me out here.  I have two Access2000 tables, one that
contains a bunch of questions and one that holds the responses to those
questions.  The schema is basically:

Questions
---------------
QuestionID : AutoIncr
QuestionText : Text

Responses
---------------
ResponseID : AutoIncr
QuestionID : Number
ResponseValue : Text

I have a simple JOIN query, in a TADOQuery that looks like:

SELECT ResponseID, QuestionText, ResponseValue
FROM Questions LEFT JOIN Responses
ON Questions.QuestionID = Responses.ResponseID

This way I can see every question whether or not they have answered it and I
use a TDBCtlGrid that contains a TDBText and TDBEdit to show the question
and corresponding response.

PROBLEM: If there is already a value there it updates it just fine.  But if
there wasn't a value to begin with I get a 'Row cannot be located for
updating. Some values may have been changed since it was last read.'  I
thought maybe you just couldn't add new records with a join like that but
when I put the exact same query into Access directly I can add records all
day.

Any hints?

Thanks

 

Re:Inserting new records with LEFT JOIN query?


What are you trying to update? If it is responses and there is no response
then you can't update a record that dosn't exist. In this case you would
need to insert instead.

Access may do this via some sort of internal playing around but I think the
behavour you see is correct.

Jeff

Quote
"Simian Jones" <simianjo...@hotmail.com> wrote in message

news:3a561004$1_1@dnews...
Quote
> All,

> Maybe someone can help me out here.  I have two Access2000 tables, one
that
> contains a bunch of questions and one that holds the responses to those
> questions.  The schema is basically:

> Questions
> ---------------
> QuestionID : AutoIncr
> QuestionText : Text

> Responses
> ---------------
> ResponseID : AutoIncr
> QuestionID : Number
> ResponseValue : Text

> I have a simple JOIN query, in a TADOQuery that looks like:

> SELECT ResponseID, QuestionText, ResponseValue
> FROM Questions LEFT JOIN Responses
> ON Questions.QuestionID = Responses.ResponseID

> This way I can see every question whether or not they have answered it and
I
> use a TDBCtlGrid that contains a TDBText and TDBEdit to show the question
> and corresponding response.

> PROBLEM: If there is already a value there it updates it just fine.  But
if
> there wasn't a value to begin with I get a 'Row cannot be located for
> updating. Some values may have been changed since it was last read.'  I
> thought maybe you just couldn't add new records with a join like that but
> when I put the exact same query into Access directly I can add records all
> day.

> Any hints?

> Thanks

Other Threads