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

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.
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
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
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
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";

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

2

View comments

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).
Blog Archive
Topics
Topics
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.