[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Non-visual data access

Posted on 2004-09-22
9
Medium Priority
?
211 Views
Last Modified: 2010-04-05
I have just begun working with SQL and Delphi and am trying to read up on it, but everything wants me to use the VCL.

I have a simple task I want to complete, and don't want any visual components to do it.

I pull data from an LDAP server and store it all in a TList.
I then want to take the data in my tlist and write it to fields in a SQL table.

Then i'll want another function to read the data that is there, store it back in my TList so I can do what I need to do with it there.

I know what connection string i want to use, etc... I just can't seem to figure out how to read/write data in my sql table without using DBGrid or anything visual.

Any help?
0
Comment
Question by:gwarguitar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12123872
you can either drop some ADOConnection and ADOQuery to your form, those are not visual components, but you can modify it's properties in the Object Inspector
or you can create those dinamically, something like this:

var
  myADOConn:TADOConnection;
  myADOQuery:TADOQuery;
const
  CONN_STR = 'Provider=SQLOLEDB.1;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=%s;Data Source=%s';
begin
  myADOConn:=TADOConnection.Create(nil);
  myADOQuery:=TADOQuery.Create(nil);
  try
    myADOConn.LoginPrompt:=False;
    myADOConn.Mode:=cmShareDenyNone;
    myADOConn.ConnectionString:=Format(CONN_STR, [
           'DBPassword', 'DBUser', 'DBDatabase', 'DBServer']);
    myADOQuery.Connection:=myADOConn;
    myADOQuery.SQL.Text:='insert into table, blablabla';
    myADOQuery.ExecSQL;
  finally
    myADOConn.Connected:=False;
    myADOQuery.Free;
    myADOConn.Free
  end
end;
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12123919
if you drop the components in the form, all you need from this code is:

myADOQuery.SQL.Text:='insert into table, blablabla'; //your query here
    myADOQuery.ExecSQL;

the rest you can change it in the Object Inspector
0
 

Author Comment

by:gwarguitar
ID: 12123945
yeah, i don't mind the components, i just want to pull the data non visually.

what about reading to my tlist?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gwarguitar
ID: 12124138
here, i'll give a more specific example...

type
  PUserInfo = ^TUserInfo;
  TUserInfo = record
    first_name : ShortString;
    last_name  : ShortString;
  end;

that's my tlist

and the fields in my db..

 [FirstName] [varchar] (35) NOT NULL ,
 [LastName] [varchar] (35) NOT NULL

there are more fields, but that will give me an idea.

so how do i loop through every item in my tlist, adding data to the db where appropriate. then the other way around?


0
 
LVL 13

Assisted Solution

by:BlackTigerX
BlackTigerX earned 500 total points
ID: 12124293
var UserInfo:TUserInfo;
begin
    for X:=0 to myList.Count-1 do //myList is your list of pointers...
    begin
      UserInfo:=TUserInfo(myList.Items[X]^); //get the user information out of the list
      myADOQuery.SQL.Text:='insert into your table (FirstName, LastName) '+
      'values ('+QuotedStr(UserInfo.first_name)+','+QuotedStr(UserInfo.last_name)+')';
      myADOQuery.ExecSQL
    end

//myADOQuery is the variable I showed you in the other example
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12124300
this part:

myADOQuery.SQL.Text:='insert into your table (FirstName, LastName) '+

needs to be whatever the name of your table is:

myADOQuery.SQL.Text:='insert into YOURTABLENAMEHERE (FirstName, LastName) '+
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12124371
> .... I just can't seem to figure out how to read/write data in my sql table without using DBGrid or anything visual.

Ofcourse you don't need DBGrid to read/write data (Data is reading and writing by TADOQuery, TADOTAble .... TQuery, TTable .... ): DBGrid is for visualization, editing and / or inserting data ... If you don't need visualization, editing and / or inserting data you may work without DBGrid and without anything visual.
0
 

Author Comment

by:gwarguitar
ID: 12126625
woohoo! that works..

what about reading to my tlist? what statement would i use for that?
0
 
LVL 17

Accepted Solution

by:
geobul earned 500 total points
ID: 12130503

  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add ('SELECT * FROM tablename');
  ADOQuery1.Open; // get dataset
  while not ADOQuery1.EOF do begin // loop dataset
    ui.first_name := ADOQuery1.FieldByName('FirstName').AsString; // read fields in a record
    ui.last_name := ADOQuery1.FieldByName('LastName').AsString;
    List1.Add(ui); // add the record to the list
    ADOQuery1.Next;
  end;
  ADOQuery1.Close;

Regards, Geo
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question