Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How Can i Create A Class Library For MSACCESS database Connection

How Can i Create A Class Library For MSACCESS database Connection

Scheduled Pinned Locked Moved C#
csharpdatabasecomhelptutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arunkumar Koloth
    wrote on last edited by
    #1

    Hi All, Iam New To C# I Writed Code Like This using System; using System.Collections.Generic; using System.Text; using System.Data.OleDb; namespace Access { public class Connection { OleDbConnection con; OleDbCommand com = new OleDbCommand(); public void connect(string connectionstring) { con = new OleDbConnection(connectionstring); con.Open(); } public void Command(string Commandtext) { OleDbCommand com = new OleDbCommand(Commandtext); } public void ExecuteNonQuery() { com.ExecuteNonQuery(); } public void CloseConnection() { con.Close(); } } } Thease Statements are not working Correctly Really I Dont Know What to Do. Can Any one Help me With A example Code? Please Help Me. Arunkumar

    T L P A 4 Replies Last reply
    0
    • A Arunkumar Koloth

      Hi All, Iam New To C# I Writed Code Like This using System; using System.Collections.Generic; using System.Text; using System.Data.OleDb; namespace Access { public class Connection { OleDbConnection con; OleDbCommand com = new OleDbCommand(); public void connect(string connectionstring) { con = new OleDbConnection(connectionstring); con.Open(); } public void Command(string Commandtext) { OleDbCommand com = new OleDbCommand(Commandtext); } public void ExecuteNonQuery() { com.ExecuteNonQuery(); } public void CloseConnection() { con.Close(); } } } Thease Statements are not working Correctly Really I Dont Know What to Do. Can Any one Help me With A example Code? Please Help Me. Arunkumar

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      You are not passing/setting the connection to the oleDBCommand. Also the object com is local to the Command method. Take a look at this tutorial[^] on msdn site.

      1 Reply Last reply
      0
      • A Arunkumar Koloth

        Hi All, Iam New To C# I Writed Code Like This using System; using System.Collections.Generic; using System.Text; using System.Data.OleDb; namespace Access { public class Connection { OleDbConnection con; OleDbCommand com = new OleDbCommand(); public void connect(string connectionstring) { con = new OleDbConnection(connectionstring); con.Open(); } public void Command(string Commandtext) { OleDbCommand com = new OleDbCommand(Commandtext); } public void ExecuteNonQuery() { com.ExecuteNonQuery(); } public void CloseConnection() { con.Close(); } } } Thease Statements are not working Correctly Really I Dont Know What to Do. Can Any one Help me With A example Code? Please Help Me. Arunkumar

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Arunkumar.Koloth wrote:

        Iam New To C#

        In that case you should spend more time studying and practicing the langauage basics before trying an advanced topic such as this.

        Arunkumar.Koloth wrote:

        Thease Statements are not working Correctly

        See my previous comment, you have nothing in the above that actually executes any of the methods in your class.

        The best things in life are not things.

        1 Reply Last reply
        0
        • A Arunkumar Koloth

          Hi All, Iam New To C# I Writed Code Like This using System; using System.Collections.Generic; using System.Text; using System.Data.OleDb; namespace Access { public class Connection { OleDbConnection con; OleDbCommand com = new OleDbCommand(); public void connect(string connectionstring) { con = new OleDbConnection(connectionstring); con.Open(); } public void Command(string Commandtext) { OleDbCommand com = new OleDbCommand(Commandtext); } public void ExecuteNonQuery() { com.ExecuteNonQuery(); } public void CloseConnection() { con.Close(); } } } Thease Statements are not working Correctly Really I Dont Know What to Do. Can Any one Help me With A example Code? Please Help Me. Arunkumar

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Right, your main problem is in your Command method; just set the CommandText property of the existing com field. You should also have the Command method accept values for Parameters.

          1 Reply Last reply
          0
          • A Arunkumar Koloth

            Hi All, Iam New To C# I Writed Code Like This using System; using System.Collections.Generic; using System.Text; using System.Data.OleDb; namespace Access { public class Connection { OleDbConnection con; OleDbCommand com = new OleDbCommand(); public void connect(string connectionstring) { con = new OleDbConnection(connectionstring); con.Open(); } public void Command(string Commandtext) { OleDbCommand com = new OleDbCommand(Commandtext); } public void ExecuteNonQuery() { com.ExecuteNonQuery(); } public void CloseConnection() { con.Close(); } } } Thease Statements are not working Correctly Really I Dont Know What to Do. Can Any one Help me With A example Code? Please Help Me. Arunkumar

            A Offline
            A Offline
            ambarishtv
            wrote on last edited by
            #5

            Hi Arun Try this

            using System;
            using System.Collections.Generic;
            using System.Text;
            using System.Data.OleDb;
            namespace Access
            {
            public class Connection
            {
            private string getConnectionString()
            {
            return "connetionString";
            }

                public static void ExecuteCommand(string command)
                {
                    OleDbConnection con;
                    OleDbCommand com;
                    try
                    {
                        con = new OleDbConnection(getConnectionString());
                        con.Open();
                        com = new OleDbCommand(command);
                        com.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        //ex shows exception
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
            

            //Call Connection Method public void MyMethord() { Connection.ExecuteCommand("command write here"); }

            -ambarish-

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups