using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Connection_Config_Class1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con1,con2;
private void btn_SQL_Click(object sender, EventArgs e)
{
MessageBox.Show(CLSConnection.SQLGetConnection().ToString());
try
{
con1 = new OleDbConnection(CLSConnection.SQLGetConnection());
//No need of adding CLSConnection's class namespace, B/c that class is with inthis namespace only..
con1.Open();
MessageBox.Show("SQL Connection State ::"+ con1.State.ToString());
if (con1.State == ConnectionState.Open)
{
lb_SQL.Text = "SQL Connection Opened..";
lb_SQL.ForeColor = Color.Green;
}
else
{
lb_SQL.Text = "SQL Connection Failed..";
lb_SQL.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
lb_SQL.Text = "SQL Connection Failed..";
lb_SQL.ForeColor = Color.Red;
MessageBox.Show(ex.Message);
}
}
private void btn_MSA_Click(object sender, EventArgs e)
{
MessageBox.Show(CLSConnection.MSAGetConnection().ToString());
try
{
con2 = new OleDbConnection(CLSConnection.MSAGetConnection());
//No need of adding CLSConnection's class namespace, B/c that class is with inthis namespace only..
con2.Open();
MessageBox.Show("MS-Access Connection State ::"+con2.State.ToString());
if (con2.State == ConnectionState.Open)
{
lb_MSA.Text = "MS-Access Connection Opened..";
lb_MSA.ForeColor = Color.Green;
}
else
{
lb_MSA.Text = "MS-Access Connection Failed..";
lb_MSA.ForeColor = Color.Red;
}
}
catch (Exception ex)
{
lb_MSA.Text = "MS-Access Connection Failed..";
lb_MSA.ForeColor = Color.Red;
MessageBox.Show(ex.Message);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace Connection_Config_Class1
{
class CLSConnection
{
//
public static string sqlconstr; // Static Data field
public static string SQLGetConnection()// Static Method
{
sqlconstr =
ConfigurationSettings.AppSettings["SQLConSetting1"].ToString();
return sqlconstr;
}
public static string msaconstr; // Static Data field
public static string MSAGetConnection()// Static Method
{
msaconstr =
ConfigurationSettings.AppSettings["AccessConSetting1"].ToString();
return msaconstr;
}
}
}
"
[?xml version="1.0" encoding="utf-8" ?>
[configuration>
[add key="SQLConSetting" value="Provider=sqloledb; Data Source=.;Initial
Catalog=master;Integrated Security=True"/>
[add key="SQLConSetting1" value="Provider=sqloledb; Data Source=.;Initial
Catalog=master;User ID=sa;Password=123"/>
[add key="AccessConSetting" value="Provider=Microsoft.JET.OLEDB4.0;data source
=.;Integrated security=true; database=master"/>
[add key="AccessConSetting1" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\EmployeeDB.mdb"/>
[!---->
[/appSettings>
[/configuration>
"
Blog Archive
-
▼
2010
(11)
-
▼
September
(7)
- DELEGATES AND EVENTS
- Difference Between ToString() vs Convert.ToString(...
- The StringBuilder and String classes provide ways ...
- C# Code: SQL & MS-Access DB Connection Class
- C# Code: Arthimatic Calculation by Taking 3 Operan...
- C# Code:Arthimatic Calculation by Taking 3 Operand...
- C# Code for Arthimatic Calculation by Taking 3 Ope...
-
▼
September
(7)
My Links
- C# Snippets: 1
- C# Snippets: 2
- XMLFOX - CSHARP SAMPLES
- Q: Export your Crystal Report data to PDF
- Q: To create a Excel report wihtout using Excel object model Ex
- Q: Using C#, How to Save,Update Data to and from XML with out using the sql server database
- Q: upload excel to SQL using C#.net,VS2005
- Q: Export DataTable to Excel using c# with Formatting Styles
- Q: Crystal report in c# .Net
- Q: Import excel into Sql server 2005 Table
- Q: READ, UPDATE & DELETE XML FILE USING X-PATH
- Q: Export Data from Listview to Excel
- Q: About GridView Data To Excel C#
- Q: Simple way to convert excel sheet to sql table
- Q: How to send data from c# file(.cs) to xslt file
- Q: How to Export and import data from sqlserver to excel sheet in vb.net
- Q: Migration of data from access to excel and vice versa
- Q: How to insert the data from excel to Database in .Net?
- Q: How can we create excel sheet in c# using data grid
- Q: DateTime Value Manipulation
- Q: create an array from a txt file
- Q: HowtoOepnandReadanExcelSpreadsheetinaListViewin.NET
- Q: How to fill data to excel
- Q: Reading Image from Excel file using C# .Net
- C# / CSharp Tutorial
- stackoverflow.com/questions
- General .NET Projects
- Sample .NET Projects with source code
- CSharpArticles
- PHPManual
- phpmanual/en/install.windows
- ProtoPage
Wednesday, September 8, 2010
C# Code: SQL & MS-Access DB Connection Class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment