Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Database connection in Delphi 8

Posted on 2004-10-18
5
Medium Priority
?
231 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 1000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

609 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