Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
OriginalGriff20-Jan-14 5:50
mveOriginalGriff20-Jan-14 5:50 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
BillWoodruff20-Jan-14 9:08
professionalBillWoodruff20-Jan-14 9:08 
QuestionCustom Data Types Pin
sunsilk1020-Jan-14 3:04
sunsilk1020-Jan-14 3:04 
AnswerRe: Custom Data Types Pin
Manfred Rudolf Bihy20-Jan-14 3:25
professionalManfred Rudolf Bihy20-Jan-14 3:25 
AnswerRe: Custom Data Types Pin
BillWoodruff20-Jan-14 5:13
professionalBillWoodruff20-Jan-14 5:13 
AnswerRe: Custom Data Types Pin
Freak3020-Jan-14 23:30
Freak3020-Jan-14 23:30 
QuestionC# with Oraclei Pin
Nightbird.14319-Jan-14 21:00
Nightbird.14319-Jan-14 21:00 
AnswerRe: C# with Oraclei Pin
V.19-Jan-14 21:49
professionalV.19-Jan-14 21:49 
My advise would be to create a new project as class library. This will be your DAL component.

Then you need to build it with some things in mind:
* You want reusability. I created an interface and inhereted for different providers (mysql, oracle, odbc connectors etc...)
* You need some operations that are able to perform select, update, ... etc. But maybe also less convenient queries (Create table, alter table, ...) Personally I create ExecuteSelect, ExecuteUpdate, ... that takes a string (the sql) and another set ExecuteSelectSafe, ExecuteUpdateSafe, ... that takes the SQL and a list of parameternames and objectvalues.
* I included support for transactions
* I created a class that holds the result. eg the ExecuteXXX class returns that result which holds: a status (OK, FAILED, ...), an exception (if status is failed), the SQL query itself, A dataset, ... etc...

Note that for some providers you'll need the dll.

When built you can or strong-name it and install to the GAC or just reference the dll in any project you want to use it. Don't be lazy on this one, because it will become your bottleneck.

This is the Interface I wrote... Don't blindly copy/paste it. Start from scratch and try to understand what you're doing. (Note: this is an older version, I actually changed the "ENUM return values" into returning a result object containing the status, exception, dataset, ...
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;


namespace Framework.Dal
{
    /// <summary>
    /// Result of the database connection and execution of SQL statements.
    /// </summary>
    public static class DBResult
    {
        //enums
        /** <summary>Status of the execution of the Query or Stored Procedure.</summary>*/
        public enum DB_STATUS
        {
            /** <summary>Undefined Status.</summary>*/
            UNDEFINED = 0,
            /** <summary>Connection with the database failed.</summary>*/
            CONNECTION_FAILED = 1,
            /** <summary>Connection with the database was OK.</summary>*/
            CONNECTION_OK = 2,
            /** <summary>The execution of the statement failed.</summary>*/
            EXECUTE_FAILED = 3,
            /** <summary>The execution of the statement was succesful.</summary>*/
            EXECUTE_OK = 4,
        }													//end enum DB_STATUS
    }														//end class DB_STATUS

    /// <summary>
    /// Interface for SQL, OleDb and Odbc database connections.
    /// </summary>
    public interface IDataBaseConnector
    {

        /// <summary>
        /// Sets the connectionstring for the database connection.
        /// </summary>
        /// <param name="connection_string">The connection string.</param>
        void SetConnection_String(string connection_string);

        /// <summary>
        /// Tests the database connection.
        /// </summary>
        /// <returns>true if connection is available.</returns>
        bool TestConnection();

        /// <summary>
        /// Executes a select statement.
        /// </summary>
        /// <param name="stmnt">The select statement to execute.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteSelect(string stmnt);

		/// <summary>
		/// Executes a select statement by using parameters to prevent SQL-Injection.
		/// </summary>
		/// <param name="command">The select statement to execute.</param>
		/// <param name="paramnames">The object array to be used for the parameters.</param>
		/// <param name="paramvals">The object array to be used for the parameters.</param>
		/// <returns>An enumeration indicating the success/failure</returns>
        DBResult.DB_STATUS ExecuteSelectSafe(string command, string[] paramnames, object[] paramvals);

        /// <summary>
        /// Executes an update statement.
        /// </summary>
        /// <param name="stmnt">The update statement to execute.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteUpdate(string stmnt);

		/// <summary>
		/// Executes an update statement by using parameters to prevent SQL-Injection.
		/// </summary>
		/// <param name="command">The update statement to execute.</param>
		/// <param name="paramnames">The string array to be used for the parameter namess.</param>
		/// <param name="paramvals">The object array to be used for the parameter values.</param>
		/// <returns>An Enum indicating Succes/Failure</returns>
        DBResult.DB_STATUS ExecuteUpdateSafe(string command, string[] paramnames, object[] paramvals);


        /// <summary>
        /// Executes an Insert statement.
        /// </summary>
        /// <param name="stmnt">The insert statement to execute.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteInsert(string stmnt);

		/// <summary>
		/// Executes an Insert statement by using parameters to prevent SQL-Injection.
		/// </summary>
		/// <param name="command">The insert statement to execute.</param>
		/// <param name="paramnames">The string array to be used for the parameter namess.</param>
		/// <param name="paramvals">The object array to be used for the parameter valuess.</param>
		/// <returns>An Enum value indicating success/failure</returns>
		DBResult.DB_STATUS ExecuteInsertSafe(string command, string [] paramnames, object [] paramvals);

        /// <summary>
        /// Executes a delete statement.
        /// </summary>
        /// <param name="stmnt">The delete statement to execute.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteDelete(string stmnt);

		/// <summary>
		/// Executes a delete statement by using parameters to prevent SQL-Injection.
		/// </summary>
		/// <param name="command">The delete statement to execute.</param>
		/// <param name="paramnames">The object array to be used for the parameter names.</param>
		/// <param name="paramvals">The object array to be used for the parameter values.</param>
		/// <returns>An Enum value indicating success/failure</returns>
        DBResult.DB_STATUS ExecuteDeleteSafe(string command, string[] paramnames, object[] paramvals);

        /// <summary>
        /// Executes a stored procedure.
        /// </summary>
        /// <param name="sp_name">The name of the stored procedure.</param>
        /// <param name="param_names">An array with the names of the parameters.</param>
        /// <param name="param_values">An array with the values of the parameters.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteStoredProcedure(string sp_name, ArrayList param_names, ArrayList param_values);

        /// <summary>
        /// Executes a non-query.
        /// </summary>
        /// <param name="stmnt">The statement to execute.</param>
        /// <returns>An integer equal to the DB_STATUS enumeration.</returns>
        DBResult.DB_STATUS ExecuteNonQuery(string stmnt);

        /// <summary>
        /// Gets the dataset of the last succesfull ExecuteSelect call.
        /// </summary>
        /// <returns>The dataset</returns>
        DataSet GetDataSet();

        /// <summary>
        /// Gets a friendly error message of the last occurred error.
        /// </summary>
        /// <returns></returns>
        string GetLastErrorMessage();

        /// <summary>
        /// Returns the tables of the database.
        /// </summary>
        /// <returns>A string containing all the tablenames.</returns>
        string[] GetTables();

        /// <summary>
        /// Returns column information of a table.
        /// </summary>
        /// <param name="tablename">The tablename for which you want the columninformation.</param>
        /// <returns>A DataColumnCollection containing all necessary information about the columns.</returns>
        DataColumnCollection GetColumnInformation(string tablename);

        /// <summary>
        /// Gets the number of rows that where affected by a previous statement.
        /// </summary>
        /// <returns>the number of rows affected.</returns>
        int GetNrOfRowsAffected();
    }														//end interface IDataBaseConnector
}															//end namespace DatabaseTools



hope this helps.

QuestionMulti Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron19-Jan-14 19:23
ptr_Electron19-Jan-14 19:23 
AnswerRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
Mycroft Holmes19-Jan-14 21:02
professionalMycroft Holmes19-Jan-14 21:02 
GeneralRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron20-Jan-14 0:40
ptr_Electron20-Jan-14 0:40 
AnswerRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
Bernhard Hiller20-Jan-14 3:47
Bernhard Hiller20-Jan-14 3:47 
GeneralRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron20-Jan-14 7:11
ptr_Electron20-Jan-14 7:11 
QuestionSuggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
ahmed_one19-Jan-14 18:48
ahmed_one19-Jan-14 18:48 
AnswerRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
Mycroft Holmes19-Jan-14 20:57
professionalMycroft Holmes19-Jan-14 20:57 
GeneralRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
ahmed_one19-Jan-14 21:11
ahmed_one19-Jan-14 21:11 
GeneralRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
Trak4Net20-Jan-14 9:01
Trak4Net20-Jan-14 9:01 
GeneralRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
ahmed_one20-Jan-14 17:05
ahmed_one20-Jan-14 17:05 
Questioncreate and use .DLL Pin
DrooBo19-Jan-14 6:28
DrooBo19-Jan-14 6:28 
SuggestionRe: create and use .DLL Pin
Richard MacCutchan19-Jan-14 6:52
mveRichard MacCutchan19-Jan-14 6:52 
AnswerRe: create and use .DLL Pin
Dave Kreskowiak19-Jan-14 6:57
mveDave Kreskowiak19-Jan-14 6:57 
AnswerRe: create and use .DLL Pin
DrooBo19-Jan-14 7:30
DrooBo19-Jan-14 7:30 
GeneralRe: create and use .DLL Pin
Dave Kreskowiak19-Jan-14 10:22
mveDave Kreskowiak19-Jan-14 10:22 
GeneralRe: create and use .DLL Pin
Richard MacCutchan19-Jan-14 22:36
mveRichard MacCutchan19-Jan-14 22:36 
AnswerRe: create and use .DLL Pin
Ron Beyer19-Jan-14 10:38
professionalRon Beyer19-Jan-14 10:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.