gwarguitar
asked on
Non-visual data access
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?
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?
if you drop the components in the form, all you need from this code is:
myADOQuery.SQL.Text:='inse rt into table, blablabla'; //your query here
myADOQuery.ExecSQL;
the rest you can change it in the Object Inspector
myADOQuery.SQL.Text:='inse
myADOQuery.ExecSQL;
the rest you can change it in the Object Inspector
ASKER
yeah, i don't mind the components, i just want to pull the data non visually.
what about reading to my tlist?
what about reading to my tlist?
ASKER
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?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this part:
myADOQuery.SQL.Text:='inse rt into your table (FirstName, LastName) '+
needs to be whatever the name of your table is:
myADOQuery.SQL.Text:='inse rt into YOURTABLENAMEHERE (FirstName, LastName) '+
myADOQuery.SQL.Text:='inse
needs to be whatever the name of your table is:
myADOQuery.SQL.Text:='inse
> .... 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.
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.
ASKER
woohoo! that works..
what about reading to my tlist? what statement would i use for that?
what about reading to my tlist? what statement would i use for that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or you can create those dinamically, something like this:
var
myADOConn:TADOConnection;
myADOQuery:TADOQuery;
const
CONN_STR = 'Provider=SQLOLEDB.1;Passw
begin
myADOConn:=TADOConnection.
myADOQuery:=TADOQuery.Crea
try
myADOConn.LoginPrompt:=Fal
myADOConn.Mode:=cmShareDen
myADOConn.ConnectionString
'DBPassword', 'DBUser', 'DBDatabase', 'DBServer']);
myADOQuery.Connection:=myA
myADOQuery.SQL.Text:='inse
myADOQuery.ExecSQL;
finally
myADOConn.Connected:=False
myADOQuery.Free;
myADOConn.Free
end
end;