Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how i can make aclass contains method connect to a database and return sqlconnectionMake a class call it dbconnection Add function
connection (string Connectionstring )to connect to data base
and return sqlsonnection Add function GetDataTable(string sql)
to return datatableAdd function ExecuteSql(string sql) to run
sql script And please make all functions static functions
This class to use it in connecting DB in the purchasing project
Posted
Updated 18-Sep-11 13:39pm
v2

Your question is not very clear, yet here is my five cents.

0) Make a class
1) Make a method
2) Look at ADO.NET[^]. This is the first in a series of articles on ADO.NET[^]


To the updated question.
My previous answer still applies. Though this statement: "And please make all functions static functions" seems to indicate you are of the belief that we'll do your homework for you. You should already have enough information to get started.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Sep-11 21:01pm    
My 5. I added a bit more concrete solution to the problem as I understood it. I thing the issue is to separate things specific to a concrete provider from the instances of the classes which can be used in any code. Please see my solution.
--SA
I would advice to look at this simple article first: Using ADO.NET for beginners[^].

Take a look at the diagram where you see relationships between DbConnection, DataAdapter and DataReader. The problem is: you cannot abstract connection from data provider. It is provider-specific. You need to create an instance of DataAdapter, DataReader or both using your connection string and some specific data provider you use. When you do it, you can return DataReader as the instance of the interface System.Data.IDataReader and the DataAdapter as the instance of the interface System.Data.IDataAdapter, System.Data.IDbDataAdapter or the abstract class System.Data.Common.DbDataAdapter (with some more capabilities), depending on your task. These instances are agnostic to the provider and you can use them in any application.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900