Search This Blog

Friday, October 3, 2014

System.Diagnostics Namespace C#

C# > System.Diagnostics

System.Diagnostics contains classes that allow to interact with 

  • system processes
  • event logs
  • performance counters
Classes





    Tuesday, September 30, 2014

    SqlClient namespace

    C# > System.Data  > SqlClient

    SqlClient namespace is the.NET Framework Data Provider for SQL Server.





    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";
    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();
                            }
                        }
                    }

                }




    Monday, September 29, 2014

    GetDrives C# Example

    C# > Files > DriverInfoGetDrives 

    Retrieves the drive names of all logical drives

    Example:
    DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
       tvLeft.Nodes.Add(d.Name);  
    }





    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

    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);   






    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();






    Bach file Current Directory Example

    Bach file > Current directory 

    set CURRENT_DIR=%CD%
    cd ..\..\install\kits
    install.bat
    cd %CURRENT_DIR%