SqlClient namespace is the.NET Framework Data Provider for SQL Server.
Search This Blog
Tuesday, September 30, 2014
SqlBulkCopy C# SQL Server import data example
C# > System.Data > SqlClient > SqlBulkCopy
SqlBulkCopy efficiently bulk load a SQL Server table with data from another source.
The data source is not limited to SQL Server, any data source can be used.
SqlBulkCopy offers a significant performance.
Example:
string sourceConnectionString = "YourSourceConnectionString";
SqlBulkCopy efficiently bulk load a SQL Server table with data from another source.
The data source is not limited to SQL Server, any data source can be used.
SqlBulkCopy offers a significant performance.
string sourceConnectionString = "YourSourceConnectionString";
string destinationConnectionString = "YourDestinationConnectionString";
using (SqlConnection sourceConnection =
new SqlConnection(sourceConnectionString))
{
sourceConnection.Open();
SqlCommand commandSourceData = new SqlCommand(
"SELECT * FROM source_table;", sourceConnection);
SqlDataReader reader = commandSourceData.ExecuteReader();
using (SqlConnection destinationConnection =
new SqlConnection(destinationConnectionString))
{
destinationConnection.Open();
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(destinationConnection))
{
bulkCopy.DestinationTableName = "dbo.destination_table";
try
{
bulkCopy.WriteToServer(reader);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
reader.Close();
}
}
}
}
Etichete:
c#,
SQL Server
Monday, September 29, 2014
GetDrives C# Example
C# > Files > DriverInfo > GetDrives
Retrieves the drive names of all logical drives
Example:
DriveInfo[] allDrives = DriveInfo.GetDrives();
Retrieves the drive names of all logical drives
Example:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
tvLeft.Nodes.Add(d.Name);
}
Etichete:
c#
Thursday, September 25, 2014
RichTextBox control insert color text
C# > RichTextBox Control > SelectionColor
Gets or sets the text color of the current text selection or insertion point.
Example
Gets or sets the text color of the current text selection or insertion point.
Example
private void AppendText(RichTextBox rtb, string text, Color color)
{
rtb.SelectionStart = rtb.TextLength;
rtb.SelectionLength = 0;
rtb.SelectionColor = color;
rtb.AppendText(text);
rtb.SelectionColor = rtb.ForeColor;
}
AppendText(richTextBox1, "Blue", Color.Blue);
AppendText(richTextBox1, "Red", Color.Red);
Etichete:
c#
Wednesday, September 24, 2014
Telerik RadGridView clear all rows
Telerik > RadGridView > Rows > Clear
Clear is a efficient solution to remove all rows since the grid's events will be suspended.
Example
this.radGridView1.Rows.Clear();
Etichete:
Telerik
Bach file Current Directory Example
Bach file > Current directory
set CURRENT_DIR=%CD%
cd ..\..\install\kits
install.bat
cd %CURRENT_DIR%
set CURRENT_DIR=%CD%
cd ..\..\install\kits
install.bat
cd %CURRENT_DIR%
Etichete:
batch file
Tuesday, September 23, 2014
Configure Jenkins to use Mercurial
Jenkins > Mercurial
Reduce unnecessary builds by specifying a comma or space delimited list of "modules" within the repository. A module is a directory name within the repository that this project lives.
Mercurial Plugin: Install the Jenkins Mercurial Plugin first (read more https://wiki.jenkins-ci.org/display/JENKINS/Mercurial+Plugin)
Source Code Management: Configure for Mercurial
Reduce unnecessary builds by specifying a comma or space delimited list of "modules" within the repository. A module is a directory name within the repository that this project lives.
To do that press advanced button:
This will detect changes only in sdks subdirectory in src directory:
Etichete:
Jenkins
Wednesday, September 17, 2014
Environment UserName property C# example
C# > System > Environment Class > UserName
UserName is used to identify the user on the current thread, the user name of the person who is logged on to Windows.
Example
UserName is used to identify the user on the current thread, the user name of the person who is logged on to Windows.
Example
string user = Environment.UserName;
Etichete:
c#
SetEnvironmentVariable C# Example
C# > System > Environment Class > SetEnvironmentVariable
SetEnvironmentVariable creates, modifies, or deletes an environment variable.
Example
SetEnvironmentVariable creates, modifies, or deletes an environment variable.
Example
Environment.SetEnvironmentVariable("VisualStudioVersion", "10.0");
Etichete:
c#
Environment Class C#
C# > System > Environment Class
Environment class is used to retrieve/change information about environment variable settings, command line arguments, call stack.
Methods:
Properties:
Environment class is used to retrieve/change information about environment variable settings, command line arguments, call stack.
Methods:
Properties:
Etichete:
c#
Wednesday, September 10, 2014
Delete directory C#
C# > Files > Directory > Delete
Deletes the specified directory.
Example
Deletes the specified directory and any subdirectories and
files in the directory.
Deletes the specified directory.
Example
Deletes the specified directory and any subdirectories and
files in the directory.
System.IO.Directory.Delete(@"c:\Temp\", true);
Etichete:
c#
Friday, August 29, 2014
How to get if is Runtime or Design Mode VB.net
VB.NET > Control > DesignMode
DesignMode returns true is a control is being used in the context of a designer.
Example:
If Me.DesignMode Then
Return
End If
DesignMode returns true is a control is being used in the context of a designer.
Example:
If Me.DesignMode Then
Return
End If
Etichete:
VB.NET
Tuesday, August 12, 2014
Typeof C# example
Etichete:
c#
Wednesday, July 30, 2014
SerialPort Class Example
C# > IO > Ports > SerialPort
SerialPort controls a serial port file resource.
Example
1. Gets all serial port names for the current computer.
SerialPort controls a serial port file resource.
Example
1. Gets all serial port names for the current computer.
List<String> serialPorts = new List<String>();
foreach (String portName in System.IO.Ports.SerialPort.GetPortNames())
{
serialPorts.Add(portName);
}
Etichete:
c#
Thursday, July 24, 2014
CAST SQL Server Example
SQL Server > Built-in Functions > CAST
CAST converts an expression of one data type to another.
Examples
CAST converts an expression of one data type to another.
CAST ( expression AS data_type )
Examples
Etichete:
SQL Server
Wednesday, July 16, 2014
ROWCOUNT SQL Server Example
SQL Server > Built-In Functions > @@ROWCOUNT
Returns the number of rows affected by the last statement.
Example:
Returns the number of rows affected by the last statement.
Example:
UPDATE Person SET Age = 31 WHERE Id = 1 IF @@ROWCOUNT = 0 PRINT 'No rows were updated';
Tuesday, June 24, 2014
Public keyword C# Example
C# > Keywords > public
Public is the most permissive access level.
It is no restrictions on accessing public members.
Example
Public is the most permissive access level.
It is no restrictions on accessing public members.
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 WindowsFormsApplication12
{
public partial class Form1 : Form
{
public class Person
{
public string Name;
public int Age;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Person p = new Person();
p.Name = "John";
p.Age = 35;
}
}
}
Etichete:
c#
Wednesday, June 18, 2014
Implement Strings Enum in C#
C# > Types > Enum > String Enum
Implement Strings Enum in C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EnumString
{
public partial class Form1 : Form
{
public enum Cars
{
[Description("Audi")] Audi,
[Description("Bmw")] Bmw,
[Description("Land Rover")] LandRover
}
public static string GetCarDescription(Enum car)
{
FieldInfo fi = car.GetType().GetField(car.ToString());
DescriptionAttribute[] da = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (da != null && da.Length > 0)
return da[0].Description;
else
return da.ToString();
}
public static IEnumerable EnumToList()
{
Type type = typeof(T);
Array vals = Enum.GetValues(type);
List valList = new List(vals.Length);
foreach (int val in vals)
{
valList.Add((T)Enum.Parse(type, val.ToString()));
}
return valList;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (Cars car in EnumToList<Cars>())
{
comboBox1.Items.Add(GetCarDescription(car));
}
}
}
}
Etichete:
c#
Subscribe to:
Posts (Atom)