Click here to Skip to main content
15,896,726 members
Articles / Database Development / SQL Server

A SQL Management Console for MSSQL 2000 & 2005, MySQL 5.0,...

Rate me:
Please Sign up or sign in to vote.
4.86/5 (14 votes)
20 Apr 2008Ms-PL4 min read 68.6K   2.5K   68  
An article on a SQL IDE for different type of RDBMS databases
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace SQLMgtConsole
{
    class DBFactory
    { 
        // Provider Independent Code for .NET Framework Data Providers
        public DataTable fnExecDBCommonQuery(string strDBProvider, DbConnection dbcConnection,
                                                string strtQueryString, ref Exception exErrHandle)
        {
            DataTable dtResult = new DataTable();
            try
            {
                if (dbcConnection != null && !strDBProvider.Trim().Equals(""))
                {
                    dbcConnection.Open();
                    // You can specify the provider here. Because it is a string,
                    // it could also be a variable that comes from a config file: 
                    DbProviderFactory dataFactory = DbProviderFactories.GetFactory(strDBProvider);
                    DbDataAdapter da = dataFactory.CreateDataAdapter();
                    da.SelectCommand = dbcConnection.CreateCommand();
                    da.SelectCommand.CommandText = strtQueryString;

                    // Fill the DataTable and bind the DataGrid 
                    da.Fill(dtResult);
                    exErrHandle = null;
                }
            }
            catch (SqlException sqlEx)
            {
                Console.WriteLine("sqlEx : " + sqlEx.Message + Environment.NewLine + sqlEx.StackTrace);
                exErrHandle = (Exception)sqlEx;
                dtResult = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ex : " + ex.Message + Environment.NewLine + ex.StackTrace);
                exErrHandle = ex;
                dtResult = null;
            }
            finally
            {
                if (dbcConnection != null)
                    dbcConnection.Close();
            }
            return dtResult;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer
Malaysia Malaysia
My blog: http://start-coding.blogspot.com/

Comments and Discussions