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
8ce79c92-6c96-4fff-902b-4b9984c3d0ab|0|.0
Tags:
SQL SERVER
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;
}
b4cd5038-6d7c-4ddc-9a34-8ec91b8f9522|0|.0
Tags:
c#
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();
}
2c78ef95-5c68-4a73-b083-d6cd0e8caad2|0|.0
Tags:
c#