A design pattern provides a framework for building an application. Design patterns makes the design process cleaner and more efficient. You can use existing design patterns to make templates for your objects and allowing you to build software faster.
Search This Blog
Thursday, November 21, 2013
Design Patterns C#
C# > Design patterns
A design pattern provides a framework for building an application. Design patterns makes the design process cleaner and more efficient. You can use existing design patterns to make templates for your objects and allowing you to build software faster.
A design pattern provides a framework for building an application. Design patterns makes the design process cleaner and more efficient. You can use existing design patterns to make templates for your objects and allowing you to build software faster.
Etichete:
c#
Singleton pattern C# Example
C# > Design Patterns > Singleton
Singleton is used to restrict instantiation of a class to one object. In this way we ensure that the class has only one instance.
When to use?
Usually singletons are used for centralized management and provide a global point of access to themselves.
Example
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
class Singleton
{
private static Singleton instance;
protected Singleton()
{
// protected constructor
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Singleton st = new Singleton(); Error 'WindowsFormsApplication1.Singleton.Singleton()' is inaccessible due to its protection level
Singleton st1 = Singleton.GetInstance();
Singleton st2 = Singleton.GetInstance(); // st2=st1
}
}
}
Singleton is used to restrict instantiation of a class to one object. In this way we ensure that the class has only one instance.
When to use?
Usually singletons are used for centralized management and provide a global point of access to themselves.
- logging
- configuration
- resources
Example
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{class Singleton
{
private static Singleton instance;
protected Singleton()
{
// protected constructor
}
public static Singleton GetInstance()
{
if (instance == null)
{
lock (typeof(Singleton))
{
instance = new Singleton();
}
}
return instance;
}
} public partial class Form1 : Form
{public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Singleton st = new Singleton(); Error 'WindowsFormsApplication1.Singleton.Singleton()' is inaccessible due to its protection level
Singleton st1 = Singleton.GetInstance();
Singleton st2 = Singleton.GetInstance(); // st2=st1
}
}
}
Etichete:
c#
Wednesday, November 20, 2013
LINQ to DataSet - Filtering with DataView C#
C# > System.Data > DataSet > Linq to DataSet
DataView can be created from a LINQ to DataSet query.
Example:
Create a DataView from a LINQ to DataSet query with a Where clause
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add("Product");
DataTable dt = ds.Tables[0];
dt.Columns.Add("id", typeof(Int32));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("quantity", typeof(Int32));
select p;
DataView view = query.AsDataView();
BindingSource bs = new BindingSource();
bs.DataSource = view;
}
void fillDataTable(DataTable dt)
{
for (int i = 0; i < 100; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "Product ";
dr[2] = i;
dt.Rows.Add(dr);
}
}
}
}
DataView can be created from a LINQ to DataSet query.
Example:
Create a DataView from a LINQ to DataSet query with a Where clause
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add("Product");
DataTable dt = ds.Tables[0];
dt.Columns.Add("id", typeof(Int32));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("quantity", typeof(Int32));
fillDataTable(dt);
EnumerableRowCollection<DataRow> query = from p in ds.Tables[0].AsEnumerable()
where p.Field<Int32>("quantity") > 50 && p.Field<Int32>("quantity") < 70select p;
DataView view = query.AsDataView();
BindingSource bs = new BindingSource();
bs.DataSource = view;
}
void fillDataTable(DataTable dt)
{
for (int i = 0; i < 100; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "Product ";
dr[2] = i;
dt.Rows.Add(dr);
}
}
}
}
Etichete:
c#
What is Oracle PL/SQL?
Oracle PL/SQL
PL/SQL is an language that was designed for processing of SQL commands.
PL/SQL stands for Procedural Language extension of SQL.
Server-side PL/SQL is stored and compiled in Oracle Database and runs within the Oracle executable.
PL/SQL is a block structured language, which means program is in logical blocks of code.
Structure
Example
Links
PL/SQL is an language that was designed for processing of SQL commands.
PL/SQL stands for Procedural Language extension of SQL.
Server-side PL/SQL is stored and compiled in Oracle Database and runs within the Oracle executable.
PL/SQL is a block structured language, which means program is in logical blocks of code.
Structure
DECLARE <declarations section> BEGIN <executable command(s)> EXCEPTION <exception handling> END; |
Example
DECLARE msg varchar2(50):= 'PL/SQL Example'; BEGIN dbms_output.put_line(msg); END ; / |
Links
Etichete:
Oracle/PLSQL
String functions SQL Server
SQL Server > Built-in Functions > String
String functions perform an operation on a string input value and return a string or numeric value.
String functions perform an operation on a string input value and return a string or numeric value.
- SUBSTRING
Etichete:
SQL Server
Operators SQL Server
SQL Server > Operators
An operator is a symbol specifying an action that is performed on expressions
Arithmetic
Relational
Set
An operator is a symbol specifying an action that is performed on expressions
Arithmetic
Relational
Set
Etichete:
SQL Server
How to get SQL Server authentication logins
SQL Server > System Views > Catalog > sys.sql_logins
sys.sql_logins returns information about SQL Server authentication logins.
Example:
SELECT m.name, m.principal_id, m.type_desc, m.password_hash FROM master.sys.sql_logins m
Result:
name principal_id type_desc password_hash
sa 1 SQL_LOGIN 0x0200D225062FC1F5301DB7D08706A19C5CC900AB979B59D33B8ACB61F5
D5FCCF9BA0CE660B47435B9A5BD1F06D63C56A4DC6FB69EA429978866AEE29FA440F4E3D
4AE336D3D2
sys.sql_logins returns information about SQL Server authentication logins.
Example:
SELECT m.name, m.principal_id, m.type_desc, m.password_hash FROM master.sys.sql_logins m
Result:
name principal_id type_desc password_hash
sa 1 SQL_LOGIN 0x0200D225062FC1F5301DB7D08706A19C5CC900AB979B59D33B8ACB61F5
D5FCCF9BA0CE660B47435B9A5BD1F06D63C56A4DC6FB69EA429978866AEE29FA440F4E3D
4AE336D3D2
Etichete:
SQL Server
Subscribe to:
Posts (Atom)