Solved

Database connection in Delphi 8

Posted on 2004-10-18
5
225 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 143
FMX enumerated colours 2 97
Mobile Keyboard covers the display of the TMemo 3 85
CheckListBox usage 3 58
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

816 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

9 Experts available now in Live!

Get 1:1 Help Now