Pages

Tuesday, 22 November 2011

ExecuteScalar

A tip from Si:
I’m not sure if this has been mentioned before BUT did you know that the ExecuteScalar method on an SqlCommand will cheerfully truncate any string returned through it? That means that XML returned from a stored procedure say may or may not be cut in half depending on its size. The solution is to use the ExecuteXmlReader method instead. Details in this link ExecuteScalar truncates

Friday, 30 September 2011

SQL Output Parameter

I don't why but any SQL Parameters that are defined as outputs are not available until the SqlDataReader has been closed.
So this works:
SqlParameter reservationNumberParameter = new SqlParameter("@ReservationNumber", SqlDbType.NVarChar, 15);
reservationNumberParameter.Direction = ParameterDirection.Output;
command.Parameters.Add(reservationNumberParameter);

reader = command.ExecuteReader();

reader.Close();

reservationNumber = Convert.ToString(reservationNumberParameter.Value);

Whereas this does not work:
SqlParameter reservationNumberParameter = new SqlParameter("@ReservationNumber", SqlDbType.NVarChar, 15);
reservationNumberParameter.Direction = ParameterDirection.Output;
command.Parameters.Add(reservationNumberParameter);

reader = command.ExecuteReader();

reservationNumber = Convert.ToString(reservationNumberParameter.Value);

reader.Close();

Monday, 22 August 2011

DataGridTextColumn Text Alignment

This technique has been superceded by this one DataGridTextColumn Text Alignment
<DataGridTextColumn.CellStyle>
  <Style>
    <Setter Property="FrameworkElement.HorizontalAlignment" Value="Right" />
  </Style>
</DataGridTextColumn.CellStyle>

Friday, 22 April 2011

jQuery Callbacks

A recent foray into jQuery land left me floundering with the callback syntax.

$("#datepicker").datepicker(
{
// The CallBack argument is an anonymous function
onSelect: function(dateText, inst)
{
// This invokes the real function
myCallBackFunction(dateText, inst);
}
}
);

// This is the real function that will
// be executed when the onSelect
// invokes its Callback
function myCallBackFunction(dateText,inst)
{
$("#selectedDate").val(dateText);
}

With a simple callback function the anonymous function can contain the processing.


$("#datepicker").datepicker(
{
// The CallBack argument is an anonymous function
onSelect: function(dateText, inst)
{
$("#selectedDate").val(dateText);
}
}
);

Saturday, 12 March 2011

ResourceStrings Access Modifier

When a new Resource file is added to a project the Access Modifier defaults to Internal.

There is a small combobox at the top of the Resource editor that allows it to be changed.

Thursday, 10 March 2011

COM Data Types

Data type conversions from COM to .Net
























IDL Type.NET Type
charSystem.SByte
shortSystem.Int16
int, long, HRESULT and SCODESystem.Int32
int64System.Int64
unsigned charSystem.Byte
unsigned shortSystem.UInt16
unsigned int and unsigned longSystem.UInt32
uint64System.UInt64
floatSystem.Single
doubleSystem.Double
BSTR, LPSTR and LPWSTRSystem.String
VARIANT_BOOLSystem.Boolean
DATESystem.DateTime
GUIDSystem.Guid
DECIMALSystem.Decimal
CURRENCYSystem.Decimal
VARIANTSystem.Object
IUnknown*System.Object
IDispatch*System.Object
void*System.IntPtr
IDispatchEx*System.Runtime.InteropServices.Expando.IExpando
IEnumVariant*System.Collections.IEnumerator










COMIDL
boolean and smallchar
wchar_tunsigned short
hyper and __int64int64
[string] char*LPSTR
[string] wchar_t*LPWSTR
byteunsigned char
unsigned hyper and unsigned __int64uint64

Wednesday, 16 February 2011

MouseOver Triggers

Here is a minimal example of changing the background colour of a TextBlock when MouseOver is detected.
<Window.Resources>
<Style TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Pink" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<TextBlock>Hello World</TextBlock>
</StackPanel>