How Can i Create A Class Library For MSACCESS database Connection
-
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 -
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 -
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. ArunkumarArunkumar.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.
-
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. ArunkumarRight, your main problem is in your
Command
method; just set theCommandText
property of the existingcom
field. You should also have theCommand
method accept values for Parameters. -
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. ArunkumarHi 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-