Wednesday, July 21, 2010
Elite For The iPhone And iPad
Server Error With Virtual Directory
Server Error in '/TestSubSite' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.Parser Error Message: Could not load file or assembly 'SControls' or one of its dependencies. The system cannot find the file specified. (D:\web\testsite\web.config line 211)
Source Error:
|
Source File: D:\web\testsite\web.config Line: 211
Thursday, July 15, 2010
How To Get DateTime In XSLT
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="urn:sample" extension-element-prefixes="msxml">
<msxsl:script language="JScript" implements-prefix="my">
function today()
{
return new Date();
}
</msxsl:script>
<xsl:template match="/">
Today = <xsl:value-of select="my:today()"/>
</xsl:template>
</xsl:stylesheet>
/// Takes a string containing XML to be parsed and a string containing the the XSLT to do the parsing.
/// </summary>
public static string XSLTransformation(string xml, string xsl)
{
// create the readers for the xml and xsl
XmlReader reader = XmlReader.Create(new StringReader(xsl));
XmlReader input = XmlReader.Create(new StringReader(xml));
// create the xsl transformer
XslCompiledTransform t = new XslCompiledTransform(true);
XsltSettings settings = new XsltSettings(false, true);
t.Load(reader, settings, null);
// create the writer which will output the transformed xml
StringBuilder sb = new StringBuilder();
XmlWriterSettings tt = new XmlWriterSettings();
//tt.Encoding = new UTF8Encoding(false);
XmlWriter results = XmlWriter.Create(new StringWriter(sb)); //, tt);
// write the transformed xml out to a stringbuilder
t.Transform(input, null, results);
// return the transformed xml
return sb.ToString();
}
Every Project Fails
Wednesday, July 14, 2010
- How Google works: http://www.ppcblog.com/how-google-works/
- How Google ranks search results: http://www.google.com/technology/pigeonrank.html
Tuesday, July 13, 2010
SQL Knowledge Base
- Getting the last inserted key (identity):
http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/ - T-SQL FOR XML Basics:
http://blah.winsmarts.com/2007-2-Bak2Basics__Learn_T-SQL_-_FOR_XML.aspx - T-SQL XML Crib-sheet:
http://www.simple-talk.com/sql/learn-sql-server/sql-server-xml-cribsheet/#fourth - Robyn Page's SQL Articles:
http://www.simple-talk.com/author/robyn-page/ - Never do this- Validating a URL in SQL:
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/validate-a-url-from-sql-server.aspx - Reading XML files into table fields:
- http://stackoverflow.com/questions/3245301/using-t-sql-to-read-an-xml-feed-directly-into-an-xml-field-in-a-table
- SSIS XML Import tutorial video:
http://msdn.microsoft.com/en-us/library/cc952927(SQL.100).aspx - Processing XSLT in SQL Server:
http://blogs.msdn.com/b/mrorke/archive/2005/06/28/433471.aspx - Numbering Rows:
http://blogs.x2line.com/al/archive/2005/11/18/1323.aspx - Rollbacks:
http://www.geekinterview.com/question_details/33247
http://msdn.microsoft.com/en-us/library/aa175920(SQL.80).aspx
Thursday, July 08, 2010
Parsing XML Into T-SQL Tables
The aim was to make a query which would take any XML and list, in one table, all the elements, their attributes and their element and attribute values of the immediate child nodes of the root node. On top of that, each immediate child of the root had to be enumerated so it could be referenced properly when being inserted into another table/s.
Example input:
<root>
<date>07/07/10</date>
<start>07/02/10</start>
<m code="AL">
<Time>10:22</Time>
<Ask>1943.25</Ask>
<Open>1940.00</Open>
</m>
<m code="AA">
<Time>14:42</Time>
<Ask>143.05</Ask>
<Open>230.50</Open>
</m>
</root>
Example output:
ElementIndex | ParentElement | FieldName | NodeType | FieldValue |
---|---|---|---|---|
1 | m | Time | element | 10:22 |
1 | m | Ask | element | 1943.25 |
1 | m | Open | element | 1940.00 |
1 | m | code | attribute | AL |
2 | m | Time | element | 14:42 |
2 | m | Ask | element | 143.05 |
2 | m | Open | element | 230.50 |
2 | m | code | attribute | AA |
And finally, the SQL...
declare @xml XML
set @xml = 'YOUR XML HERE'
create table #t
(
rownum int,
xmlextract xml
)
-- populate the table with the child nodes of the root, if they have their own sub nodes
insert into #t
SELECT
row_number() over(order by getdate()) as 'RowNum',
pref.query('.') as XmlExtract
FROM
@xml.nodes('/*/*') AS extract(pref)
WHERE
pref.value('./*[1]', 'nvarchar(50)') IS NOT NULL
SELECT distinct rownum 'ElementIndex', ParentName 'ParentElement', FieldName, NodeType, FieldValue FROM
(
-- selects the attributes and their values from the xml
SELECT DISTINCT
rownum,
SubEl.SubElem.value('local-name(..)', 'nvarchar(50)') AS ParentName,
SubEl.SubElem.value('local-name(.)', 'nvarchar(50)') AS FieldName,
'attribute' as NodeType,
SubEl.SubElem.value('.', 'nvarchar(150)') AS FieldValue
FROM
#t
CROSS APPLY
xmlextract.nodes('//@*') AS SubEl(SubElem)
UNION
-- selects the inner element and their values from the xml
SELECT
rownum,
SubEl.SubElem.value('local-name(..)', 'nvarchar(50)') AS ParentName,
SubEl.SubElem.value('local-name(.)', 'nvarchar(50)') AS FieldName,
'element' as NodeType,
SubEl.SubElem.value('.', 'nvarchar(150)') AS FieldValue
FROM
#t
CROSS APPLY
xmlextract.nodes('/*/*') AS SubEl(SubElem)
) as tmp
ORDER BY ElementIndex, ParentElement, FieldName
drop table #t
However, for performance and tidy-up reasons, when using this code in a stored procedure, you may want to use a table variable. Here's the modified version:
declare @xml XML
set @xml = 'YOUR XML HERE'
declare @t table
(
rownum int,
xmlextract xml
)
-- populate the table with the child nodes of the root, if they have their own sub nodes
insert into @t
SELECT
row_number() over(order by getdate()) as 'RowNum',
pref.query('.') as XmlExtract
FROM
@xml.nodes('/*/*') AS extract(pref)
WHERE
pref.value('./*[1]', 'nvarchar(50)') IS NOT NULL
SELECT distinct rownum 'ElementIndex', ParentName 'ParentElement', FieldName, NodeType, FieldValue FROM
(
-- selects the attributes and their values from the xml
SELECT DISTINCT
rownum,
SubEl.SubElem.value('local-name(..)', 'nvarchar(50)') AS ParentName,
SubEl.SubElem.value('local-name(.)', 'nvarchar(50)') AS FieldName,
'attribute' as NodeType,
SubEl.SubElem.value('.', 'nvarchar(150)') AS FieldValue
FROM
@t
CROSS APPLY
xmlextract.nodes('//@*') AS SubEl(SubElem)
UNION
-- selects the inner element and their values from the xml
SELECT
rownum,
SubEl.SubElem.value('local-name(..)', 'nvarchar(50)') AS ParentName,
SubEl.SubElem.value('local-name(.)', 'nvarchar(50)') AS FieldName,
'element' as NodeType,
SubEl.SubElem.value('.', 'nvarchar(150)') AS FieldValue
FROM
@t
CROSS APPLY
xmlextract.nodes('/*/*') AS SubEl(SubElem)
) as tmp
ORDER BY ElementIndex, ParentElement, FieldName
References:
Tuesday, July 06, 2010
SQLXML Gymnastics
SELECTID,Name as 'Names/FirstName',Surname as 'Names/LastName'FROMNamesFOR XML PATH('person'), ROOT('people')
<Elements><Element><Index>1</Index><Type>3M</Type><Code>AL</Code><Time>1900-01-01T10:22:00</Time></Element><Element><Index>2</Index><Type>3M</Type><Code>AA</Code><Time>1900-01-01T19:00:00</Time></Element></Elements>
SELECTr.value('Index[1]', 'int') [Index],r.value('Type[1]', 'nvarchar(50)') [Type],
r.value('Code[1]', 'nvarchar(50)') [Code],
r.value('Time[1]', 'datetime') [Time]FROM@content.nodes('/Elements/*') AS records(r)
<Elements><Element><Index>1</Index><Type>3M</Type><Code>AL</Code><Time>1900-01-01T10:22:00</Time></Element><Element><Index>2</Index><Type>3M</Type><Code>AA</Code><Time>1900-01-01T19:00:00</Time></Element></Elements>
SELECTEl.Elem.value('(Index)[1]', 'int') [Index],SubEl.SubElem.value('local-name(.)', 'varchar(100)') AS 'Field Name',SubEl.SubElem.value('.', 'varchar(100)') AS 'Field Value'FROM@content.nodes('/Elements/Element') AS El(elem)CROSS APPLYEl.Elem.nodes('*') AS SubEl(SubElem)WHERESubEl.SubElem.value('local-name(.)', 'varchar(100)') <> 'Index'
Index | Field Name | Field Value |
1 | Type | 3M |
1 | Code | AL |
1 | Time | 1900-01-01T10:22:00 |
2 | Type | 3M |
2 | Code | AA |
2 | Time | 1900-01-01T19:00:00 |
SELECTelem.value('local-name(..)', 'nvarchar(10)') AS 'Parent Name',elem.value('local-name(.)', 'nvarchar(10)') AS 'Attribute Name',elem.value('.', 'nvarchar(10)') AS 'Attribute Value'FROM@content.nodes('//@*') AS El(elem)
SELECT DISTINCT r.value('fn:local-name(.)', 'nvarchar(50)') FieldNameFROM @xml.nodes('/*/*') AS records(r)
SELECTpref.query('.') as SomeXml,FROM@xml.nodes('/*/*') AS Content(pref)
SELECTrow_number() over(order by cast(pref.query('.') as nvarchar(max))) as 'RowNum',pref.query('.') as XmlExtractFROM@xml.nodes('/*/*') AS extract(pref)WHEREpref.value('./*[1]', 'nvarchar(10)') IS NOT NULL
DECLARE @content XMLSET @content ='<people><person id="1" bimble="1"><firstname bobble="gomble">John</firstname><surname>Doe</surname></person><person id="2" bimble="11"><firstname bobble="zoom">Mary</firstname><surname>Jane</surname></person><person id="4" bimble="10"><firstname bobble="womble">Matt</firstname><surname>Spanner</surname></person></people>'
-- All attributes with parent element nameSELECTelem.value('local-name(..)', 'nvarchar(10)') AS 'Parent Name',elem.value('local-name(.)', 'nvarchar(10)') AS 'Attribute Name',elem.value('.', 'nvarchar(10)') AS 'Attribute Value'FROM@content.nodes('//@*') AS El(elem)-- Inner element values (with index attribute)SELECTEl.Elem.value('(@*)[1]', 'int') [Index],SubEl.SubElem.value('local-name(.)', 'nvarchar(10)') AS 'Field Name',SubEl.SubElem.value('.', 'nvarchar(10)') AS 'Field Value'FROM@content.nodes('/*/*') AS El(elem)CROSS APPLYEl.Elem.nodes('*') AS SubEl(SubElem)-- Second level element attributes (with index attribute)SELECTEl.Elem.value('(@*)[1]', 'int') [Index],SubEl.SubElem.value('local-name(.)', 'nvarchar(10)') AS 'Field Name',SubEl.SubElem.value('.', 'nvarchar(10)') AS 'Field Value'FROM@content.nodes('/*/*') AS El(elem)CROSS APPLYEl.Elem.nodes('@*') AS SubEl(SubElem)-- Third level element attributes (with index attribute)SELECTEl.Elem.value('(@*)[1]', 'int') [Index],SubEl.SubElem.value('local-name(.)', 'nvarchar(10)') AS 'Field Name',SubEl.SubElem.value('.', 'nvarchar(10)') AS 'Field Value'FROM@content.nodes('/*/*') AS El(elem)CROSS APPLYEl.Elem.nodes('*/@*') AS SubEl(SubElem)-- All element attributes and parent element name (with index attribute)SELECT DISTINCTEl.Elem.value('(@*)[1]', 'int') [Index],SubEl.SubElem.value('local-name(..)', 'nvarchar(10)') AS 'Parent Name',SubEl.SubElem.value('local-name(.)', 'nvarchar(10)') AS 'Field Name',SubEl.SubElem.value('.', 'nvarchar(10)') AS 'Field Value'FROM@content.nodes('/*/*') AS El(elem)CROSS APPLYEl.Elem.nodes('//@*') AS SubEl(SubElem)ORDER BY [Index]
- http://beyondrelational.com/blogs/jacob/archive/2010/05/30/select-from-xml.aspx
- http://stackoverflow.com/questions/3180834/retrieving-xml-element-name-using-t-sql/3180868#3180868
- http://stackoverflow.com/questions/2266132/how-can-i-get-a-list-of-element-names-from-an-xml-value-in-sql-server
- http://www.stylusstudio.com/sqlxml_tutorial.html
- http://blogs.msdn.com/b/simonince/archive/2009/04/24/flattening-xml-data-in-sql-server.aspx
- http://centricle.com/tools/html-entities/
Monday, July 05, 2010
Some Tech Stuff I Really Must Read
- http://www.dotnetcurry.com/ShowArticle.aspx?ID=515&AspxAutoDetectCookieSupport=1
- http://www.highoncoding.com/Articles/697_Persisting_CheckBox_State_While_Paging_in_GridView_Control.aspx
- http://csharpbits.notaclue.net/2010/06/securing-dynamic-data-4-replay.html
- http://dotnetslackers.com/articles/aspnet/ASP-NET-MVC-2-0-Areas.aspx
- http://www.c-sharpcorner.com/UploadFile/vendettamit/733/Default.aspx
- http://geekswithblogs.net/WinAZ/archive/2010/04/07/using-linq-distinct-with-an-example-on-asp.net-mvc-selectlistitem.aspx
Friday, July 02, 2010
Server Application Unavailable
Adding And Subtracting Dates In T-SQL
@declare myDate datetimeset @myDate = (select dateadd(dd,10,getdate()))select @myDate
@declare myDate datetimeset @myDate = (select dateadd(mm,-1,@dateArg))select @myDate
Thursday, July 01, 2010
Splitting Strings in T-SQL Using XML
Event Firing Delegate Handlers For Basic Use Controls
public delegate void ChartSelected(int chartId);public ChartSelected onChartSelected = null;
selector.onChartSelected = MyEventMethod;
private void ChartSelected(int chartId){// do something}
if (onChartSelected != null)onChartSelected(someSelectedValue);