Hello all! I have been searching for weeks now for a solution to this and still cannot find any.
I am just trying to learn the basics of connecting to a Access database and sending and retrieving data.
So far, i have my form setup with edit boxes and a button etc, and a simple ADOQuery thrown on the page which is connected to my Access file through the connection string.
So far i have been successful in grabing the data from the database and showing it in a EDIT box by doing this
This works and puts the information into the boxes. But now i am stuck on how do i go about putting data IN the database?Code:procedure TForm3.Button1Click(Sender: TObject); begin q1.Active:=true; while not q1.Eof do begin Edit1.Text:=q1.FieldByName('iName').Text; Edit2.Text:=q1.FieldByName('iSize').Text; Edit3.Text:=q1.FieldByName('iColour').Text; q1.Next; end; end;
So if someone was to enter something into a EDIT box, and i wanted to take that information and put it into a database, how do i go about this?
Hope this all makes sense! It's driving me crazy now![]()
You really need to learn SQL. The standard way to get data in and out of a database is to set the SQL string in your ADOQuery and then call either the Open method (for a select statement) or Execute method (for insert, update, etc).
Ok thank you. I have managed after looking around here, to get it to post information into the database, and retrieve it. I'm having one last problem i was hoping you could help me with though.
How would i go about entering data from, lets say edtbox.text into the sql database? Or data saved into a variable into the database? I've been searching google all day with no luck!
Code:ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('INSERT INTO mytable (field1, field2, field3) VALUES (''value1'',''value2'','''+edtbox.txt+''')'); ADOQuery1.Execute;
So close!!!
I have this
It runs ok, but whatever i type into the EDT box when its running, does not get saved into the database, Instead it simply saves +UserName.text+ into the database. Doh!Code:with q1 do begin Active:=False; SQL.Clear; SQL.Add('Insert INTO Marble (Username) VALUES (''+UserName.text+'')'); ExecSQL; end;
Woops just noticed my error as soon as i posted! Was missing some ' signs in there. Works a charm now, thank you SO much you have no idea how much you have helped me. I have spent countless hours on google and in books trying to find this simple answer!
Thanks once again, very much appreciated.
I'm glad I could help.
Hello its me again! Just a quick error that keeps popping up when trying to insert data into 2 tables. It keeps telling me
Syntax Error in INSERT INTO statement
The code i have is this
Any ideas on this one?Code:procedure TFrmRegistration.Button1Click(Sender: TObject); begin with q1 do begin Active:=False; SQL.Clear; SQL.Add('Insert INTO Marble (Username,Password) VALUES('''+EdtUserName.text+''','''+Edit1.text+''')'); ExecSQL; end;
What details?
How do you mean?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks