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

2

View comments

--Make the System ignore the constraint

ALTER TABLE PK_ConstraintsTableName NOCHECK CONSTRAINT ALL

--Now Delete

DELETE

FROM TableName

WHERE WhereClause

--Put the contraints back

ALTER TABLE PK_ConstraintsTableName CHECK CONSTRAINT ALL

May 28th, 2015

SQL  - Using Case Statement To Update A Table: 

CREATE TABLE #t1 (ID INT, name VARCHAR(10), val1 INT, val2 INT)

INSERT #t1  (ID , name , val1 , val2 )

SELECT 1, 'aaa01', 10, 100

UNION ALL

SELECT 2, 'bbb01', 20, 200

UNION ALL

SELECT 3, 'aaa02', 30, 300

UNION ALL

SELECT 4, 'bbb02', 40, 400

S

Here is an example of what different join produce in SQL.

SQL Complex Grouping using group sub-string.

The Comma Separated Value (CSV) file contains data that (as the name suggests) are separated by commas.  In C# they can easily be split into an array by using Data.Split(',').  The problem occurs when data contains a comma.

2

For a project I needed to create a string wrapper function.

The wrapper function had to follow these rules.

1: Each line has a prefix.

2: Each line may not exceed 80 charachters, including the prefix.

private DataTable ReadAsDataTable(string file, bool hasHeader, char seperator)

{

DataTable dt = new DataTable();

StreamReader reader = new StreamReader(file);

string line = string.Empty;

string[] data = null;

int counter = 0;

while (reader.Peek() != -1)

{

line = reader.ReadLine();

data = l

//A simple RegEx validotor.

private DateTime GetDate(DateTime inputDate, string differenceType, bool add, int difference)

{

DateTime result = inputDate;

if (!add)

{

//Substraction

difference = -1 * difference;

}

switch (differenceType.ToUpper())

{

case "DAYS":

result = new DateTime(inputDate.Year, inputDate.Month, i

private void AddImageToThumbnail(string[] images)

{

int top = 0;

int ht = 150;

int counter = 0;

PictureBox[] pictures = new PictureBox[images.Length];

if (images.Length > 0)

{

//The panel pnlThumbnail will hold thumbnail pictures.

public string[] GetAllFilesInDirectory(string path, string pattern = "*.*", SearchOption options = SearchOption.TopDirectoryOnly)

{

if (path.Trim().Length == 0)

return null; //Error handler can go here

if ((pattern.Trim().Length == 0) || (pattern.Substring(pattern.Length - 1) == "."))

return nu

public string GetLastFileInDirectory(string directory, string pattern = "*.*")

{

if (directory.Trim().Length == 0)

return string.Empty; //Error handler can go here

if ((pattern.Trim().Length == 0) || (pattern.Substring(pattern.Length - 1) == "."))

return string.Empty; //Error handler can go her

3

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml;

using System.IO;

using System.Xml.Serialization;

//using System.Data;

using System.Data.SqlClient;

namespace zSharp2010.XMLToDB

{

public class Employee

{

public int ID { get; set; }

Let me first define the Person Class

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace zSharp2010.Serializer

{

[Serializable()]

public class Person

{

public int ID { get; set; }

public string Name { get; set; }

public DateTime DOB { get; set;

SELECT *

FROM TableName

WHERE NOT (FieldName IS NULL)

In VB6 you may catch err as:

Private Sub DivideByZero()

On Error GoTo Err_Handler

Dim num As Integer

Dim zero As Integer

num = 100 / zero

Exit_Eop:

Exit Sub

Err_Handler:

MsgBox ("Error Code : " & Err.number & vbCrLf & "Error Message : " & Err.Description)

End Sub

In C# the equivalent woul

2

Reading from App.config file:

using System.Configuration;

To read from app.config file you may use the following code:

private string ReadFromAppConfig(string key)

{

return ConfigurationManager.AppSettings[key];

}

To write to app.config file you may use the following code:

private void Write

1

Don't forget to put:

cmd.CommandType = CommandType.StoredProcedure;

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.

booleanExpression ? trueValue : falseValue;

Example:  string itemText = count > 1 ? "items" : "item";

booleanExpression ? trueValue : falseValue;

Example:  string itemText = count > 1 ? "items" : "item";

2

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.

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

{

by

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;

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.

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;

in

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 = da

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace zSharp2010.Dictionary

{

class cDictionary

{

//Create the dictionary.

public bool IsPalindrome(string stringToCheck)

{

char[] rev = stringToCheck.Reverse().ToArray();

return (stringToCheck.Equals(new string(rev), StringComparison.OrdinalIgnoreCase));

}

Lets say we have two tables

Property Table:

And user table:

We need results in the format:

DECLARE @tblProperties table (PropID int, Property varchar(20), Value varchar(20))

DECLARE @tblUsers table (UserID int, Name varchar(20), PropID Int)

INSERT  @tblProperties (PropID, Property, Value)

SEL

--Creat a table containing some words.

--USE cursor to remove invalid words from a table.

--Creat a table containing bad words

DECLARE @tblWordsToAvoidList table (sInvalidWords varchar(255))

INSERT @tblWordsToAvoidList (sInvalidWords)

SELECT ( 'aaa')

UNION ALL

SELECT ( 'eee')

--Creat a table containing some words.

If you are getting this error check the following:

1: Right click on References

2: Add the reference to the assembly that is missing (this might be another project that you have).

Simplest code to OCR an image using Microsoft Office's Imaging functionality (requires MS-Office 2007 or later, imaging components must be installed and MODI must be added to references).

7

using ADOX; //Requires Microsoft ADO Ext. 2.8 for DDL and Security

using ADODB;

public bool CreateNewAccessDatabase(string fileName)

{

bool result = false;

ADOX.Catalog cat = new ADOX.Catalog();

ADOX.Table table = new ADOX.Table();

//Create the table and it's fields.

7

Use [DataBase]

ALTER TABLE Schema.TableName

ADD FieldName Bit NOT NULL DEFAULT 0 WITH VALUES

public bool IsDate(object value)

{

bool result = false;

string strDate = value.ToString();

try

{

DateTime dt = DateTime.Parse(strDate);

if(dt != DateTime.MinValue && dt != DateTime.MaxValue)

result = true;

}

catch (Exception ex)

{

result = false;

}

return result;

}

public bool IsNumeric(string value)

{

bool result = false;

try

{

Convert.ToInt64(value);

result = true;

}

catch (Exception ex)

{

result = false;

}

return result;

}

To implement VB like Input Box in C# you may use the following code:

________________________________________________________________________

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.

1

For a project I needed to figure the dates of first and last day of the week, month, quarter

and year for a given date.

2

A simple encoding method. Uses ASCII encoding.

Strings are immutable - meaning the space allocated in memory is fixed. If two strings are concatenated, .net internally creates another string. The string builder is muatble, meaning the space allocated in memory is dynamic.

If two stringbuilders are concatenated, no new object is created.

Constructs: Is a method that runs when a new instance at class is created. It is called Sub New. Sub New may have arguments. Constructs may be overloaded.

Events: Different from VB6.

Class ClassName

Event EventName ( .. )

RaiseEvent EventName ( ..

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