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

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

SELECT *

FROM   #t1

1 aaa01 10 100

2 bbb01 20 200

3 aaa02 30 300

4 bbb02 40 400

--Update rows 1 and 3

UPDATE #t1 

SET val2 = CASE 

WHEN ID = 1 THEN 1000

WHEN ID =3 THEN 3000

ELSE Val2

END

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.  To overcome this problem, any data that contains comma is enclosed with double quotes ("").

The following function can split a csv data into array and preserve the double quoted fields.  This is a sample function, you pass a single comma separated line of data.
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.

3: If the data on a line is less than 80 charachters (including prefix), then buffer it with space characters.

4: Total number of lines may not exceed 3, so there could only be three lines. We drop the rest of the characters if it exceeds three lines.

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 = line.Split(seperator);

if (hasHeader)

{

if (counter == 0)

{

foreach (string item in data)

{

dt.Columns.Add(item);

}

}

else

dt.Rows.Add(data);

}

else

dt.Rows.Add(data);

counter++;

}

rea

//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, inputDate.Day).AddDays(difference);

break;

case "MONTHS":

result = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day).AddMonths(difference);

break;

case "YEARS":

result = new DateTime(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.

pnlThumbnail.AutoScroll = true;

foreach (string image in images)

{

try

{

pictures[counter] = new PictureBox();

pictures[counter].Parent = pnlThumbnail;

pictures[counter].Top = top;

pictures[counter].Height = ht;

pictures[counter].Width = pnlThumbnail.
Blog Archive
Topics
Topics
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.