WormsWorms
asked on
Dates and Delphi 7 and Access 97 and TADO*
OK. I am trying to insert some information into a table
I have dates in it.
so I have a table
emp_id, birthdate, name
I have a TADOConnection and a TADOQuery. I can successfully select using the query. I am now trying to insert.
I have tried
ADOQuery1.SQL.Add('INSERT into mytable emp_id, birthdate, name VALUES('
ADOQuery1.SQL.Add(QuotedSt r('10')+', ');
ADOQuery1.SQL.Add(QuotedSt r('10/10/2 001')+',') ;
ADOQuery1.SQL.Add(QuotedSt r('My name')+')');
ExecSQL;
And I get an error like this:
-------------------------- -
Debugger Exception Notification
-------------------------- -
Project Project1.exe raised exception class EOleException with message 'Data type mismatch in criteria expression'. Process stopped. Use Step or Run to continue.
-------------------------- -
OK Help
-------------------------- -
What does that mean? Any idea how I fix that?
Thanks
I have dates in it.
so I have a table
emp_id, birthdate, name
I have a TADOConnection and a TADOQuery. I can successfully select using the query. I am now trying to insert.
I have tried
ADOQuery1.SQL.Add('INSERT into mytable emp_id, birthdate, name VALUES('
ADOQuery1.SQL.Add(QuotedSt
ADOQuery1.SQL.Add(QuotedSt
ADOQuery1.SQL.Add(QuotedSt
ExecSQL;
And I get an error like this:
--------------------------
Debugger Exception Notification
--------------------------
Project Project1.exe raised exception class EOleException with message 'Data type mismatch in criteria expression'. Process stopped. Use Step or Run to continue.
--------------------------
OK Help
--------------------------
What does that mean? Any idea how I fix that?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and what type is emp_id in database?
if some numeric then you must ommit QuotedStr:
ADOQuery1.SQL.Add('INSERT into mytable (emp_id, birthdate, name) VALUES(10,'
ADOQuery1.SQL.Add(QuotedSt r('2001101 0')+',');
ADOQuery1.SQL.Add(QuotedSt r('My name')+')');
or if this is some autoincrement then ommit this field at all.
mo.
if some numeric then you must ommit QuotedStr:
ADOQuery1.SQL.Add('INSERT into mytable (emp_id, birthdate, name) VALUES(10,'
ADOQuery1.SQL.Add(QuotedSt
ADOQuery1.SQL.Add(QuotedSt
or if this is some autoincrement then ommit this field at all.
mo.
ASKER
Sorry, I didn't copy my example very well. I have the statement as
INSERT into mytable (emp_id....) VALUES (....)
INSERT into mytable (emp_id....) VALUES (....)
ASKER
I also tried ommitting the QuotedStr for my integer, but it also doesn't work.
My actual query is very long. So I am running this test query to try to get the date in. I am positive it is the date.
I will try that format that you suggest.
My actual query is very long. So I am running this test query to try to get the date in. I am positive it is the date.
I will try that format that you suggest.
by using Parameters..
ADOQuery1.SQL.Text := 'INSERT into mytable (emp_id, birthdate, name) VALUES (:emp_id, :birthdate, :name)';
with ADOQuery1.Parameters do begin
ParamByName('emp_id').Valu e := '10';
ParamByName('birthdate').V alue := '20011010';
ParamByName('name').Value := 'My name';
end;
ADOQuery1.ExecSQL;
wbr, mo.
ADOQuery1.SQL.Text := 'INSERT into mytable (emp_id, birthdate, name) VALUES (:emp_id, :birthdate, :name)';
with ADOQuery1.Parameters do begin
ParamByName('emp_id').Valu
ParamByName('birthdate').V
ParamByName('name').Value := 'My name';
end;
ADOQuery1.ExecSQL;
wbr, mo.
ASKER
Switching to the YYYYMMDD still doesn't help.
WormsWorms is frustrated.
I can insert an integer and a string. I just can't insert anything with a date.
WormsWorms is frustrated.
I can insert an integer and a string. I just can't insert anything with a date.
ASKER
The field is a DateTime field in Access 97 if that matters
ASKER
with ADOQuery1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO table1 (field,intfield,datefield) VALUES (:FIELD, :INTFIELD, :DATEFIELD)');
Parameters.ParamByName('FI ELD').Valu e := QuotedStr(edit1.text);
Parameters.ParamByName('IN TFIELD').V alue := '10';
Parameters.ParamByName('DA TEFIELD'). Value := '20021010';
ExecSQL;
end;
This is exactly what I have.
Close;
SQL.Clear;
SQL.Add('INSERT INTO table1 (field,intfield,datefield)
Parameters.ParamByName('FI
Parameters.ParamByName('IN
Parameters.ParamByName('DA
ExecSQL;
end;
This is exactly what I have.
ASKER
sorry, the above works perfect without the date stuff, as soon as I put the date stuff in it dies with that same error.
if emp_id is integer then use
with ADOQuery1.Parameters do begin
ParamByName('emp_id').Valu e := 10;
optionally, if problem remains, you can explicitly set parameter data type (I thin you need it for date type only):
ParamByName('birthdate').D ataType := ftDate;
ParamByName('birthdate').V alue := '20011010';
benefits of using parmeters - you you get better readable code (no such QuotedStr etc.)
mo.
with ADOQuery1.Parameters do begin
ParamByName('emp_id').Valu
optionally, if problem remains, you can explicitly set parameter data type (I thin you need it for date type only):
ParamByName('birthdate').D
ParamByName('birthdate').V
benefits of using parmeters - you you get better readable code (no such QuotedStr etc.)
mo.
then try to set parameter datatype to ftDateTime
mo.
mo.
ASKER
I now get this error:
-------------------------- -
Debugger Exception Notification
-------------------------- -
Project Project1.exe raised exception class EOleException with message 'Application uses a value of the wrong type for the current operation'. Process stopped. Use Step or Run to continue.
-------------------------- -
OK Help
-------------------------- -
When I use the following code:
with ADOQuery1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO table1 (field,intfield,datefield) VALUES (:FIELD, :INTFIELD, :DATEFIELD)');
Parameters.ParamByName('FI ELD').Valu e := QuotedStr(edit1.text);
Parameters.ParamByName('IN TFIELD').V alue := '10';
Parameters.ParamByName('DA TEFIELD'). DataType := ftDate;
Parameters.ParamByName('DA TEFIELD'). Value := '20021010';
ExecSQL;
end;
I am not understanding why this doesn't work. I have tried all kinds of variations on this to no avail.
I appreciate your helping mocarts. Any more ideas?
--------------------------
Debugger Exception Notification
--------------------------
Project Project1.exe raised exception class EOleException with message 'Application uses a value of the wrong type for the current operation'. Process stopped. Use Step or Run to continue.
--------------------------
OK Help
--------------------------
When I use the following code:
with ADOQuery1 do begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO table1 (field,intfield,datefield)
Parameters.ParamByName('FI
Parameters.ParamByName('IN
Parameters.ParamByName('DA
Parameters.ParamByName('DA
ExecSQL;
end;
I am not understanding why this doesn't work. I have tried all kinds of variations on this to no avail.
I appreciate your helping mocarts. Any more ideas?
ASKER
ftDateTime results in the same error as above.
grrrrrrrrrrrrrrrrrrr
grrrrrrrrrrrrrrrrrrr
Hi mo, don't waste your time. See:
https://www.experts-exchange.com/questions/20549398/MS-Access-and-Delphi.html
Regards, Geo
https://www.experts-exchange.com/questions/20549398/MS-Access-and-Delphi.html
Regards, Geo
ASKER
What is the issue geobul?
Do you know the answer?
I can give you points if you want. I really don't care.
Do you know the answer?
I can give you points if you want. I really don't care.
ASKER
There, you got your points.
Now, can you help me with this?
Now, can you help me with this?
I don't care about points. I haven't said that I should get any points. It's a matter of ... (you name it, I wont). You asked a question and received so many good examples. I don't think the experts here would like to be used that way. I take it as incorrect behaviour.
ASKER
Yah. Whatever.
mocarts, I will give you some points cuz you helped lots, even if we didnt' get it to work.
WormsWorms
mocarts, I will give you some points cuz you helped lots, even if we didnt' get it to work.
WormsWorms
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
appendix,
the parametertype of the dateparameter is ftString
meikl ;-)
the parametertype of the dateparameter is ftString
meikl ;-)
btw. i used access2000,
hope this doesn't matter ;-)
hope this doesn't matter ;-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
WormsWorms:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
ASKER
If you have an example doing it both ways that works, I will add in an extra 125 points.
Which is the better way to do it?
Thanks