Wednesday, November 04, 2009

Credit Card Number validation C#


using System.Text;


public bool IsValidNumber(string cardNumber)
{
const string allowed = "0123456789";
int i;
StringBuilder cleanNumber = new StringBuilder();

for (i = 0; i < cardNumber.Length; i++)
{
if (allowed.IndexOf(cardNumber.Substring(i, 1)) >= 0)
cleanNumber.Append(cardNumber.Substring(i, 1));
}

if (cleanNumber.Length <> 16)
return false;

for (i = cleanNumber.Length + 1; i <= 16; i++)
cleanNumber.Insert(0, "0");

int multiplier, digit, sum, total = 0;
string number = cleanNumber.ToString();

for (i = 1; i <= 16; i++)
{
multiplier = 1 + (i % 2);
digit = int.Parse(number.Substring(i - 1, 1));
sum = digit * multiplier;
if (sum > 9)
sum -= 9;
total += sum;
}

return (total % 10 == 0);

}

Friday, September 25, 2009

Replication Techniques

There are three different replication techniques available. They are snapshot replication, merge replication and transactional replication.

Snapshot replication is a single unidirectional push of data. When updated data is fed from the publisher to the subscribers, all of the data is sent each time.

Merge replication is a bidirectional replication that transmits data either in real time, or on a schedule. Merge replication is the only bidirectional replication technique available.

Transactional replication is unidirectional from the publisher to the subscribers. Data can be sent on a schedule or in real time. As data is transmitted to the subscriber, all data changes are processed in the order they were made on the publisher.

Friday, July 24, 2009

clean database log.

dump transaction GeminiExperiments with no_log

dbcc checkdb(GeminiExperiments)

Thursday, July 23, 2009

search object in DB

Select * From sysobjects Where name like '%objectname%'

search for column in DB

SELECT b.TABLE_NAME AS TableName, a.COLUMN_NAME
FROM (SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS) AS a INNER JOIN
(SELECT TABLE_NAME, TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES
WHERE (TABLE_TYPE = 'base table')) AS b ON a.TABLE_NAME = b.TABLE_NAME
WHERE (a.COLUMN_NAME = 'ColumnSearched')

Monday, July 20, 2009

send query from email from database

EXEC msdb.dbo.sp_send_dbmail
@recipients='maia.eliozashvili@vancleef.com',
@subject = 'SQL Mail Test',
@body_format = 'html', --text or html
@body = 'body1' ,
@query = 'use vcadata
select
itemno
from itemmaster
where
year(createdate)=year(getdate()) and month(createdate)=month(getdate())',
@attach_query_result_as_file = 0
--@query_attachment_filename ='Results.txt'