Solved

Database connection in Delphi 8

Posted on 2004-10-18
5
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 135
How to make Sign in, using Clientdataset? 1 39
Broadcast a message using ICS 2 48
TAction.OnAfterExecute? 2 30
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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