Create XML using SQL Query in SQL Server 2008

In this blog I will show how to create XML using Query:

SELECT TOP 1000 [Code]
      ,[Name]
      ,[Price]
  FROM [Temp].[dbo].[Product]
  FOR XML RAW ('Product'),
  ROOT ('Products');

Here SQL statement “FOR XML RAW” creates one XML node for every corresponding row in database and columns will be created as attributes of that XML node.
Output:

<Products>
<Product Code="1" Name="Tea" Price="10.0000"/>
<Product Code="2" Name="Coffee" Price="25.0000"/>
</Products>

SQL ELEMENTS create Elements instead of Attributes in xml

SELECT TOP 1000 [Code]
      ,[Name]
      ,[Price]
  FROM [Temp].[dbo].[Product]
  FOR XML RAW ('Product'),
ROOT ('Products'),
ELEMENTS;

Output:

<Products>
<Product>
  <Code>1</Code>
  <Name>Tea</Name>
  <Price>10.0000</Price>
</Product>
<Product>
  <Code>2</Code>
  <Name>Coffee</Name>
  <Price>25.0000</Price>
</Product>
</Products>

isNumber() fuction in c#

You have a string value in your C# program and want to find out if it a numeric value.
Double.TryParse method, which returns true if the input string is a number. Here we see how you can use Double.TryParse to test number strings.

public static bool IsNumeric(string s)
{
    double Result;
    return double.TryParse(s, out Result);  
}        
 
string value = "143";
if (IsNumeric(value)) 
{
  // do something
}
Check string is number,double.tr

Thanks

How to open jQuery UI Dialog from codebehind

In this blog I will show how to open jQuery UI Dialog from codebehind. Basically what we are going to do is render the neccessary JS code for UI dialog from codebehind and when the page will render, it will show the dialog.

Here is Code:

<%@ Page Language="C#" AutoEventWireup="true"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ashish's Blog</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("$(function() { ");
sb.Append(" $('#dialog').dialog({");
sb.Append("    width: 350");
sb.Append(" });");
sb.Append("});");
Page.ClientScript.RegisterStartupScript(typeof(Page), "myscript", sb.ToString(), true);
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div id="dialog" style="display: none">
Welcome to Ashish's Blog
</div>
<asp:Button ID="Button1" runat="server" Text="Test" OnClick="Button1_Click" />
</form>
</body>
</html>

Thanks