Solved

Database connection in Delphi 8

Posted on 2004-10-18
5
227 Views
Last Modified: 2011-09-20
I would need some examples like connecting to MSACCESS , MSSQL, Firebird and MySQL(without using mySQL specific components)  and WITHOUT using BDP (that is a must)
So I would need a simple example with a dbgrid that shows on runtime :) a dataset from a Query.
Thisa should not be difficult for a experienced programmer .

I do really need source code for it.
If you can give me answers for all the databases above I will raise the points.
Thanks
0
Comment
Question by:Ghitza
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12345444
Hello

  You can use OleDb data provider to work with any database has OleDb data provider drivers

Here's an example with access database

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
  Cn : OleDbConnection;
  Da : OleDbDataAdapter;
  Ds : Dataset;
begin
  Cn := OleDbConnection.Create;
  Cn.ConnectionString := 'provider=Microsoft.Jet.OLEDB.4.0;data source=c:\mydb.mdb';
  da := OleDbDataAdapter.Create('Select * from Employees',Cn);
  ds := Dataset.Create;
  Da.Fill(Ds,'Employees');
  DataGrid1.DataSource := Ds.Tables[0];
end;

If you would like to use the SqlServer, you will need just to change the Connection string and all the other code will work fine
  Cn.ConnectionString := 'provider=SQLOLEDB;data source=MySqlSrv;initial catalog=northwind';

If you want a better performance with SqlServer, you should use Sqlclient data provider instead of OleDb data provider, it's the fastest way to work with sql server, but it's work only with Sql server 7/2000

it's similar to above code, but instead of using OleDbConnection it will be SqlConnection, and methods will be remain the same in most cases

also there are .Net data provider for other database, like oracle, Mysql and FireBird,

Use OleDb data provider if you would like to use the same code with multiple databases, i'm not sure if there's free OleDb provider for MySql and FireBird, but I think both of them have ODBC, so you can use ODBC .net DataProvider too :-)

I hope that help you a little, if you have more question, plz let us know ;-)

Regards,
Mohammed

0
 
LVL 3

Author Comment

by:Ghitza
ID: 13284431
Could you give me a link for a project that does the above ?
Please.
I'll give you the points after i get the example.
Thanks
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 250 total points
ID: 13293341
Hi Ghitza,

>>Could you give me a link for a project that does the above ?
The project is just a sample I made for you, Just start new winforms project, and add reference to System.Data.OleDb, and drop a button and dataGrid

and write the code above in OnClick event of button

for other DB, look at this site for the connectionString for many Databases

http://www.connectionstrings.com

if you need more info, just tell ;-)

Regards,
Mohammed
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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