Oledb and SQL Clients

While dealing with database stuff in .Net, we might worked with Oledb and SQL Clients. Here are, some of the methods which help us to get the database tables, views, primary keys...etc

OLEDB Client/ SQL Client

Namespace

System.Data.OleDb/ System.Data.SqlClient

ConnectionString

Provider=SQLOLEDB.1;Persist Security Info=False;User ID={user};Password={password};Initial Catalog={Database};Data Source={host name/IP};

Server={host name/IP}; Database={dbname}; User ID={user}; Password={sqlServerPassword};

For various connection strings, have a look at connectionstrings

Getting Table list from database

DataTable dtObj = {connection}.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object() {null, null, null, "Table"});

DataTable dtObj = {connection}.GetSchema("Tables");

Getting Views List

DataTable dtObj = {connection}.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object() {null, null, null, "View"});

DataTable dtObj = {connection}.GetSchema("Views");

Getting Stored procedures List

DataTable dtObj = {connection}.GetOleDbSchemaTable(OleDbSchemaGuid.Procedures, new Object() {null, null, null, "Views"});

DataTable dtObj = {connection}.GetSchema("Procedures");

Getting Primary keys defined in the tables

OleDbSchemaGuid.PrimaryKeys

DataTable dtObj = {connection}.GetSchema("Indexes");

Bulk insert

OledbAdapter.Update(DataTable)

SqlBulkCopy

Hence the options are vast in the Oledb and SQLClient namespaces, I have presented few things here :).

Comments

Popular posts from this blog

DataTable ExtendedProperties

Storing Images in MySQL database

XML Documentation comments