SQL commands Overview

by pietman 27. August 2009 21:41

Capturing Errors and Rowcount at once (only avail for one SQL command - therefore grab both at once)
SELECT * FROM customer
SELECT @RowCount = @@ROWCOUNT, @Error = @@ERROR

Declaring vars:
DECLARE @j varchar(10)

Casting:
CAST(@@ROWCOUNT AS varchar(12))

Temp tables:
CREATE TABLE #Temp (i int, j varchar(10))
INSERT INTO #Temp (i, j) VALUES (1, 'First Row')
INSERT INTO #Temp (i, j) VALUES (1, 'Second Row')
GO

 

other interresting examples:

select n as [Matched state], a as Episodes  , b as Isolates from
(
SELECT 'Matched' as n, 1024 as a, 1024 as b
union SELECT 'Partially' , 12 ,12
union SELECT'No Match' as n , 33 as a ,27 as b
) as t

Tags:

SQL SERVER

iterating through a CheckBoxList

by pietman 24. August 2009 18:35

foreach (ListItem b in CheckBoxLab.Items)
{
       if (b.Selected)
       .......

 also to clear all the select boxes (select none funtion):

foreach (ListItem l in ((ListItemCollection)CheckBoxLab.Items))
{
       l.Selected = false;
}

Tags:

c#

UTF8/String coversions (byte[] / string convert)

by pietman 5. August 2009 18:48
Here follow some really usefull UTF8/String coversions below: 

They are usually used for converting streams to strings:

using System.Text;

 

private String UTF8ByteArrayToString(Byte[] characters)
{  
    UTF8Encoding encoding = new UTF8Encoding(); 
    String constructedString = encoding.GetString(characters); 
    return (constructedString);
} 
           

private Byte[] StringToUTF8ByteArray(String pXmlString)
{    
    UTF8Encoding encoding = new UTF8Encoding();    
    Byte[] byteArray = encoding.GetBytes(pXmlString);    
    return byteArray;
}

 

		

//Stream to String
ms.Position = 0;
using (StreamReader sr = new StreamReader(ms))
{
    string content = sr.ReadToEnd();
    SaveInDB(ms);
}

//String to Stream
string content = GetFromContentDB();
byte[] byteArray = Encoding.ASCII.GetBytes(content);
MemoryStream ms = new MemoryStream(byteArray); 
byte[] outBuf = ms.GetBuffer(); //error here



using(MemoryStream stream = new MemoryStream())
    {
        stream.Position = 0;
        var sr = new StreamReader(stream);
        string myStr = sr.ReadToEnd();
    }

Tags:

c#

About ...

pietman celliersPietman Celliers
Bitlink  Ltd
bitlinkit.com