Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: ADO and Access question!

  1. #1
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    ADO and Access question!

    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

    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;
    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?

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: ADO and Access question!

    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).
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Re: ADO and Access question!

    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!

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: ADO and Access question!

    Code:
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('INSERT INTO mytable (field1, field2, field3) VALUES (''value1'',''value2'','''+edtbox.txt+''')');
    ADOQuery1.Execute;
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Re: ADO and Access question!

    So close!!!

    I have this

    Code:
    with q1 do begin
      Active:=False;
      SQL.Clear;
      SQL.Add('Insert INTO Marble (Username) VALUES (''+UserName.text+'')');
      ExecSQL;
    end;
    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!

  7. #6
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Re: ADO and Access question!

    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.

  8. #7
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: ADO and Access question!

    I'm glad I could help.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  9. #8
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Re: ADO and Access question!

    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

    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;
    Any ideas on this one?

  10. #9
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: ADO and Access question!

    What details?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  11. #10
    Trix09's Avatar
    Trix09 is offline Newbie
    Join Date
    Apr 2009
    Posts
    8
    Rep Power
    0

    Re: ADO and Access question!

    How do you mean?

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-24-2010, 01:14 PM
  2. Question:technical question answering system algorithm?
    By vbehzadan in forum General Programming
    Replies: 1
    Last Post: 04-28-2010, 12:41 PM
  3. Array access through pointers vs. array access through indexes
    By DarkLordoftheMonkeys in forum C and C++
    Replies: 9
    Last Post: 01-16-2010, 05:01 PM
  4. QUESTION Strcat/Strstr/strcpy Question
    By wgre0111 in forum C and C++
    Replies: 1
    Last Post: 10-19-2008, 03:12 PM
  5. Question About RAM Access
    By Negative_3 in forum C and C++
    Replies: 1
    Last Post: 11-20-2007, 10:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts