Solved

Database connection in Delphi 8

Posted on 2004-10-18
5
223 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:mnasman
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:
mnasman 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now