Thread View: borland.public.cppbuilder.database.ado
14 messages
14 total messages
Started by Sudesh
Mon, 18 Feb 2008 11:59
ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Mon, 18 Feb 2008 11:59
Date: Mon, 18 Feb 2008 11:59
22 lines
1669 bytes
1669 bytes
Hello, I hope this is correct NG to ask my questions. With ADOConnection and Microsoft.Jet.OLEDB.4.0 I have managed to connect and read a simple MS Access database. I am displaying records in DBGrid. Can somebody please quickly guide me how to do the following? 1. Insert/delete/update records 2. Carry out SQL to filter records (and update DBGrid) something like below SELECT student_name,student_score FROM marks WHERE student_name = "foo" or SELECT student_name,student_score FROM marks WHERE student_score > 80 3. if application is to be deployed on another PC or network what is required? (BDS2006) Thanks, Sudesh
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Tue, 19 Feb 2008 02:01
Date: Tue, 19 Feb 2008 02:01
2 lines
1163 bytes
1163 bytes
no answer?:-( sudesh
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Clayton Arends
Date: Thu, 21 Feb 2008 16:27
Date: Thu, 21 Feb 2008 16:27
67 lines
3896 bytes
3896 bytes
"Sudesh" <sudeshc@vfemail.net> wrote in message
news:47b97333@newsgroups.borland.com...
> I hope this is correct NG to ask my questions.
It is. However, this question has been asked hundreds of times in the past.
Use a newsgroup search tool like google groups (http://groups.google.com)
and a search string of something like "borland ado insert record" as a
start.
> Can somebody please quickly guide me how to do the following?
> 1. Insert/delete/update records
If you want to use an easy visual interface then you can drop a TDBNavigator
on the form and hook it to the same datasource that you have hooked to your
grid and dataset. It has buttons for "Insert", "Edit", "Delete". After the
insert/edit operations you'll need to click "Post".
If you want to do these tasks in code there are methods of TDataSet (which
TADODataSet, TADOTable, and TADOQuery descend from):
// Adding a new record
ADODataSet1->Append();
// Set the values of your fields, there are various ways to do this
ADODataSet1->Fields->Fields[0]->Value = 1;
ADODataSet1->Fields->Fields[1]->AsInteger = 700;
ADODataSet1->FieldByName("Description")->Value = String("Example");
ADODataSet1->FieldValues["SomeField"] = Null();
// Save the changes
ADODataSet1->Post();
// Updating the current record
ADODataSet1->Edit();
// Set the values, use the same way as above
// Save the changes
ADODataSet1->Post();
// Deleting the current record
ADODataSet1->Delete();
> 2. Carry out SQL to filter records (and update DBGrid)
> something like below
One way is to use TADOQuery instead of TADOTable. Drop the TADOQuery
component on your form, hook into it just like you did before, set its SQL
property to whatever you want, open it (or set active to true) just like
TADOTable.
> 3. if application is to be deployed on another PC or network what is
> required?
The following packages are some of what you'll need. rtl, dbrtl, adortl,
vcl, and vcldb. Note, their names are different depending on the VCL
version you are using. They will have a 70 after their name in your case
(vcl70.bpl for example). You will also need the borlandmm.dll and
cc3270mt.dll. However, instead of relying on others here to tell you what
you'll need you should use tdump (do a google groups search to learn its
tricks) or a tool like dependency walker (http://dependencywalker.com).
These tools show you which dll/bpl files are used by the exe/dll.
If you build your exe standalone then you won't need to distribute anything
with your app (unless you have manually loaded DLLs). You may need to
download and install some ADO (OLE DB) drivers for the PC depending on what
DBMS you are attempting to connect to.
HTH,
Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Thu, 21 Feb 2008 18:11
Date: Thu, 21 Feb 2008 18:11
21 lines
1707 bytes
1707 bytes
Hi Clayton:
Thank you very much for quick response.
I could not get one thing working. Could you please tell me what's wrong
below:
ADOQuery1->SQL->Clear();
ADOQuery1->Close();
ADOQuery1->SQL->Add("SELECT * FROM marks ");
ADOQuery1->SQL->Add("WHERE student_score > 25");
ShowMessage(ADOQuery1->SQL->Text);
ADOQuery1->Open();
//ADOQuery1->ExecSQL();
ADOQuery1->Active = false;
With this code, I still see all the records in DBGrid instead of records
having score >25.
is ExecSQL() required or Open() and Active is ok?
Sudesh
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Thu, 21 Feb 2008 18:18
Date: Thu, 21 Feb 2008 18:18
12 lines
1574 bytes
1574 bytes
Hi Clayton Could you please elaborate this more? (I have earlier used Paradox which is i think obsolete now??) What all DBMS can be used and corresponding requirements at the end user. > You may need to download and install some ADO (OLE DB) drivers for the PC > depending on what DBMS you are attempting to connect to. > > HTH, > Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Clayton Arends
Date: Thu, 21 Feb 2008 20:41
Date: Thu, 21 Feb 2008 20:41
42 lines
2677 bytes
2677 bytes
"Sudesh" <sudeshc@vfemail.net> wrote in message
news:47bdbf12@newsgroups.borland.com...
> I could not get one thing working. Could you please tell me what's wrong
> below:
>
> ADOQuery1->SQL->Clear();
> ADOQuery1->Close();
Personally, I'd put the close before the clear. Also note, when you clear
SQL TADOQuery will implicitly close the database. I'd still leave the call
to close in there to make it obvious what you are doing.
> ADOQuery1->SQL->Add("SELECT * FROM marks ");
> ADOQuery1->SQL->Add("WHERE student_score > 25");
> ShowMessage(ADOQuery1->SQL->Text);
> ADOQuery1->Open();
Looks fine.
> //ADOQuery1->ExecSQL();
> ADOQuery1->Active = false;
Remove these two lines.
> With this code, I still see all the records in DBGrid instead of records
> having score >25.
I assume the grid's DataSource property references a datasource on your form
(ie. DataSource1). The datasource's DataSet property should be linked to
ADOQuery1. If that's how things are configured then you should only be
seeing records with student_score > 25. If you can't get this to work then
in the IDE switch to your form's designer view. Type ALT+F12 to switch to
edit the DFM of the form. Select all, copy, and paste this in your response
to my post.
> is ExecSQL() required or Open() and Active is ok?
ExecSQL() is used to execute commands that return no data like INSERT,
UPDATE, and DELETE. Use Open() or "Active = true" to open a SELECT command.
Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Clayton Arends
Date: Thu, 21 Feb 2008 20:56
Date: Thu, 21 Feb 2008 20:56
40 lines
3454 bytes
3454 bytes
"Sudesh" <sudeshc@vfemail.net> wrote in message news:47bdc08c@newsgroups.borland.com... >> You may need to download and install some ADO (OLE DB) drivers for the PC >> depending on what DBMS you are attempting to connect to. > > Could you please elaborate this more? (I have earlier used Paradox which > is > i think obsolete now??) > > What all DBMS can be used and corresponding requirements at the end user. ADO uses the OLEDB drivers that have been installed on a system to access a DBMS. All Windows installations have some pre-installed drivers. Jet (Access) for example comes standard. There are also some stock Microsoft drivers to access ODBC datasources, MS SQLServer, and a poor Oracle driver implementation (it's there, but don't use it). If you want to access an Oracle database you will need to download Oracle's OLEDB driver and install it on the system. There are similar drivers for other DBMS like FoxPro, and many others. I believe there is no Paradox native OLEDB driver. To access Paradox you will need to install the ODBC driver and use the stock "Microsoft OLE DB Provider for ODBC Drivers" option. ODBC was the precursor to ADO. It was the first attempt to allow Windows applications to access any database from a common architecture. Chances are if the database you are connecting to is really old then it will have an ODBC driver and therefore can be used via ADO through the above mentioned OLEDB driver. Your end-users will need to install whatever drivers they need to access the databases that your programs will connect to. If you design your program to connect to any DBMS then you can leave it up to them to download the appropriate OLEDB drivers. They will just need to be able to configure their connection(s) in your app. If you only work with one or two DBMS then you can provide a link for your users to grab the latest OLEDB drivers or install them as part of your product's installation. As I said before though, I shy away from installing drivers for my users. Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Fri, 22 Feb 2008 03:11
Date: Fri, 22 Feb 2008 03:11
9 lines
1603 bytes
1603 bytes
yes this is what was missing. thanks for pointing out the mistake. works fine! Thanks, Sudesh > I assume the grid's DataSource property references a datasource on your > form (ie. DataSource1). The datasource's DataSet property should be > linked to ADOQuery1. If that's how things are configured then you should > only be seeing records with student_score > 25.
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Fri, 22 Feb 2008 03:12
Date: Fri, 22 Feb 2008 03:12
10 lines
1659 bytes
1659 bytes
Hi Clayton: Thank you so much. You have given me a fair idea. a few more questions, appreciate if you can answer: 1. any tips for fast operations and warnings about the things one shouldn't do. 2. any guidelines in operating in Client/Server mode. 3. can you point me a good reference weblink/source for general database information. Thanks again. Sudesh
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Clayton Arends
Date: Fri, 22 Feb 2008 06:00
Date: Fri, 22 Feb 2008 06:00
31 lines
2349 bytes
2349 bytes
"Sudesh" <sudeshc@vfemail.net> wrote in message news:47be3d98@newsgroups.borland.com... > 1. any tips for fast operations and warnings about the things one > shouldn't > do. If you find yourself running select queries behind the scenes then you can take advantage of the "forward-only" cursor type. This cursor achieves better performance (when the ado driver and DBMS support it). Forward-only will *not* work with dbgrid, dbnavigator, etc. Set the CacheSize property to something reasonable like 1024. This reduces the number of round trips to retrieve your data. As for what *not* to do I don't really have any tips. Once you play with ADO for a little bit you will discover what its limitations are. > 2. any guidelines in operating in Client/Server mode. Sorry, if you have specific questions then I can try to help you. > 3. can you point me a good reference weblink/source for general database > information. Again, sorry. I get most of my information via web searches or by just playing around. I will occassionally come across a good reference but I haven't bookmarked any. Happy coding, Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Fri, 22 Feb 2008 18:32
Date: Fri, 22 Feb 2008 18:32
4 lines
1388 bytes
1388 bytes
thanks again Clayton for your help. let me play with it. sudesh
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Tue, 26 Feb 2008 03:07
Date: Tue, 26 Feb 2008 03:07
14 lines
1821 bytes
1821 bytes
let me give you a simple example. a quiz program. database and quiz application exe will reside on server and program will be accessed from a number of clients, say 300. Concurrent read (for accessing questions)and write (saving marks at the end of quiz time) operation will be required. any tips for this? which is the best and fastest database? MS Access is ok? Thanks, Sudesh >> 2. any guidelines in operating in Client/Server mode. > > Sorry, if you have specific questions then I can try to help you. >
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Clayton Arends
Date: Tue, 26 Feb 2008 13:58
Date: Tue, 26 Feb 2008 13:58
39 lines
3294 bytes
3294 bytes
"Sudesh" <sudeshc@vfemail.net> wrote in message news:47c38262@newsgroups.borland.com... > let me give you a simple example. a quiz program. > database and quiz application exe will reside on server and program will > be accessed from a number of clients, say 300. Concurrent read (for > accessing questions)and write (saving marks at the end of quiz time) > operation will be required. > any tips for this? If you are not concerned about security then you can go with a simple client/server model. All clients would have direct access to the database tables and would be able to read and write as needed. This might become problematic if you have some adventursome students that write custom applications to look at the table structure and adjust their answers (or hack the answers of others). If you are concerned with security then depending on the database you can configure each user to be able to only perform certain tasks like inserting records on particular tables (the quiz answers table, for example). Or, if that's not possible you could also take a 3 tier approach where you write a server application that resides on the database server (or at least on the same side of the firewall) that serves questions to the clients and reads answers from the clients. You will need to look into how to write TCP/Client and TCP/Server apps using Indy or other tools to complete this task. > which is the best and fastest database? MS Access is ok? MS Access is okay for multiple concurrent reads but I have read that it does not work very well for multiple concurrent writes. I don't have the details I just remember this being a problem for a lot of people in the past. A better choice is SQL Server. You can also go with MySQL, Oracle Lite, SQL Server Express, etc. Some may have nominal fees depending on your uses. Note, if you go with the 3-tier approach MS Access will work fine since you can serialize all access to the database behind-the-scene. Clayton
Re: ADOConnection, ADOTable, ADOQuery Basics
Author: Sudesh
Date: Tue, 26 Feb 2008 17:57
Date: Tue, 26 Feb 2008 17:57
2 lines
1408 bytes
1408 bytes
Thanks Clayton. Sudesh
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads