1. The process cannot access the file 'c:\temp\Query.txt' because it is being used by another process.

    Try the following code, however be very careful since you could end up reading the contents of the same file.

    private string ReadFileContents(string fileName)
    {
     string sourceText = string.Empty;
     try
     {
      //The next line will give an error if the file is already open by some other process.
      //using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None))

      //The next line will work even if the file is open by another process. 
      //However, be careful since you can be reading the contents of the same file again and again.
      using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
      {
       using (StreamReader sr = new StreamReader(fs, Encoding.ASCII))
       {
        sourceText = sr.ReadToEnd();
       }
      }
     }
     catch (Exception ex)
     {
      MessageBox.Show(ex.Message);
     }
     return sourceText;
    }
    0

    Add a comment

  2. booleanExpression ? trueValue : falseValue;
                Example:  string itemText = count > 1 ? "items" : "item";

    0

    Add a comment

  3. booleanExpression ? trueValue : falseValue;
                Example:  string itemText = count > 1 ? "items" : "item";

    2

    View comments

  4. Using VS2008, I occasionally get
    “Error while trying to run project: Unable to start debugging.  
    The Microsoft Visual Studio Remove Debugging Monitor has been closed on the remote machine”.



    To solve this problem:
    (i)                  Close the Visual Studio.
    (ii)                Open task manager and make sure that “devenv.exe” or “devenv.exe*32” are not running.  If they are close them by selecting them and then click on “End Process”




    0

    Add a comment

  5.         public int OctToDecimal(string data)
            {
                int result = 0;
                char[] numbers = data.ToCharArray();
                int ASCIIZero = 48;
                int ASCIIEight = 56;
                try
                {
                    if (!IsNumeric(data))
                        error = "Invalid Value - This is not a numeric value";
                    else
                    {
                        for (int counter = numbers.Length; counter > 0; counter--)
                        {
                            byte[] ascii = Encoding.ASCII.GetBytes (numbers[counter - 1].ToString ());
                            if ((int.Parse ( ascii[0].ToString ()) < ASCIIZero ) && (int.Parse ( ascii[0].ToString ()) > ASCIIEight ))
                                error = "Invalid Value - This is not a oct number";
                            else
                            {
                                int num = int.Parse(numbers[counter - 1].ToString());
                                int exp = numbers.Length - counter;
                                result += (Convert.ToInt16(Math.Pow(8, exp)) * num);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                return result;
            }
    0

    Add a comment

  6.         public string DecimalToOct(string data)
            {
                string result = string.Empty;
                int rem = 0;
                try
                {
                    if (!IsNumeric(data))
                        error = "Invalid Value - This is not a numeric value";
                    else
                    {
                        int num = int.Parse(data);
                        while (num > 0)
                        {
                            rem = num % 8;
                            num = num / 8;
                            result = rem.ToString() + result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                return result;
            }
    0

    Add a comment



  7. DECLARE @tblName VarChar(50) @tblName VarChar(50)

    DECLARE @columns VarChar(5000) @columns VarChar(5000)

    DECLARE @query VarChar(8000) @query VarChar(8000)

    DECLARE @id int @id int

    --Initialize the table and id.

    SELECT @tblName = 'tableName' @tblName = 'tableName'

    SELECT @id = 1234

    @id = 1234



    --GET the column names

    SELECT @columns = CASE

    WHEN @columns IS NULL THEN

    column_name

    ELSE

    @columns + ', ' + column_name

    END @columns = CASE

    WHEN @columns IS NULL THEN

    column_name

    ELSE

    @columns + ', ' + column_name

    END WHEN @columns IS NULL THEN

    column_name

    ELSE

    @columns + ', ' + column_name

    END ELSE

    @columns + ', ' + column_name

    END + ', ' + column_name

    END END

    FROM information_schema.columns information_schema.columns

    WHERE table_name = @tblName table_name = @tblName

    --Show all columns

    SELECT @columns

    @columns



    --Create query

    SET @query = '' @query = ''

    SELECT @query = ' INSERT ' + @tblName + '(' + @columns + ')' +

    ' SELECT ' + @columns +

    ' FROM ' + @tblName + ' WHERE ID = ' + convert(varchar(10), @id) @query = ' INSERT ' + @tblName + '(' + @columns + ')' +

    ' SELECT ' + @columns +

    ' FROM ' + @tblName + ' WHERE ID = ' + convert(varchar(10), @id)' SELECT ' + @columns +

    ' FROM ' + @tblName + ' WHERE ID = ' + convert(varchar(10), @id)' FROM ' + @tblName + ' WHERE ID = ' + convert(varchar(10), @id)

    --Show query

    SELECT @query

    @query



    --Execute the query

    Exec (@query)(@query)








    Source: http://aspadvice.com/blogs/ssmith/archive/2007/01/18/COPY-One-Table-Row-in-SQL.aspx/archive/2007/01/18/COPY-One-Table-Row-in-SQL.aspx
    0

    Add a comment

  8. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace zSharp2008.zMath
    {
        class cMath
        {
            string error = string.Empty;
            public string Error
            {
                get
                {
                    return error;
                }
            }

            public string DecimalToBinary(string data)
            {
                string result = string.Empty;
                int rem = 0;
                try
                {
                    if (!IsNumeric(data))
                        error = "Invalid Value - This is not a numeric value";
                    else
                    {
                        int num = int.Parse(data);
                        while (num > 0)
                        {
                            rem = num % 2;
                            num = num / 2;
                            result = rem.ToString() + result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                return result;
            }
            private bool IsNumeric(string number)
            {
                bool result = false;
                try
                {
                    int temp = int.Parse(number);
                    result = true;
                }
                catch (Exception ex)
                {
                    //Do nothing.
                }
                return result;
            }
        }
    }
    0

    Add a comment

  9. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace zSharp2008.zMath
    {
        class cMath
        {
            string error = string.Empty;
            public string Error
            {
                get
                {
                    return error;
                }
            }
            public int BinaryToDecimal(string data)
            {
                int result = 0;
                char[] numbers = data.ToCharArray();
                try
                {
                    if (!IsNumeric(data))
                        error = "Invalid Value - This is not a numeric value";
                    else
                    {
                        for (int counter = numbers.Length; counter > 0; counter--)
                        {
                            if ((numbers[counter - 1].ToString() != "0") && (numbers[counter - 1].ToString() != "1"))
                                error = "Invalid Value - This is not a binary number";
                            else
                            {
                                int num = int.Parse(numbers[counter - 1].ToString());
                                int exp = numbers.Length - counter;
                                result += (Convert.ToInt16(Math.Pow(2, exp)) * num);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                return result;
            }

            private bool IsNumeric(string number)
            {
                bool result = false;
                try
                {
                    int temp = int.Parse(number);
                    result = true;
                }
                catch (Exception ex)
                {
                    //Do nothing.
                }
                return result;
            }
        }
    }
    0

    Add a comment

  10. using System;

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

    namespace zSharp2010.Dictionary
    {
    class cDictionary
    {
    //Create the dictionary.
    private Dictionary dictionary = new Dictionary();

    ///
    /// Populate the dictionary with key and customer.
    ///
    public void SetValues()
    {
    for (int i = 1; i <= 10; i++)
    {
    //Use AAA, BBB, CCC etc as name.
    char letter = (char) (i + 64);
    Customer customer = new Customer();
    customer.ID = i * 10;
    customer.Name = letter.ToString () + letter.ToString () + letter.ToString ();
    dictionary.Add(i, customer);
    }
    }

    public string GetValues(int key)
    {
    string result = string.Empty;
    //If key is valid then return the key value.
    if (key != 0)
    {
    Customer customer = dictionary[key];
    result += string.Format("{0} : {1}, {2}\r\n", key, customer.ID.ToString(), customer.Name);
    }
    //else return the complete dictionar information.
    else
    {
    for (int i = 01; i <= dictionary.Count; i++)
    {
    Customer customer = dictionary[i];
    result += string.Format("{0} : {1}, {2}\r\n", i, customer.ID.ToString(), customer.Name);
    }
    }
    return result;
    }
    }

    //The customer class.
    class Customer
    {
    public int ID { get; set; }
    public string Name{get; set;}
    }
    }
    }

    0

    Add a comment

Blog Archive
Topics
Topics
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.