DotNet Friends

October 23, 2009

HierarchyId Data Type

Here I Explained the New Data Type in Sqlserver 2008.

What is HierarchIyd Data Type? 

HierarchyId data type is a variable length System Data Type.

What is the use of HierarchyId Data Type?

Represent position in a hierarchy manner.

HierarchyId does not automatically represent a tree, it is depend on how to application generate and assign HierarchyId values.

HierarchyId have following properties:

1) Extremely Compact

2) Comparison is in depth-first-order.

3) Support for arbitrary insertions and deletions.

Limitation Of HierarchyId :

1)  Does not automatically represent a Tree

2) It is up to Application to manage concurrency in generating and assigning HierarchyId Values.

3) There is no any dependency on HierarchyId relationship.

 

See more about HierarchyId example refer :

http://amitpatriwala.wordpress.com/2009/10/23/sql-server-2008-feature-part1/

Reference Site :

http://technet.microsoft.com/en-us/library/bb677290.aspx

Sql Server 2008 Feature – Part1

Here I am explaining Sql Server 2008 Key Features.

1) Initializing variable when you declare

declare @val as int =0
declare @currentdate as datetime = getdate
()
print @val
print @currentdate

2) Compound assignment operators

–operator like +=,-=,/=,*/,%=
declare @val as int = 0
set @val += 10
;
print @val

3) Add multiple row in single Insert Statement

CREATE TABLE Employee
(
EmpId int,
EmpCode varchar(50),
EmpName varchar(50)
);

INSERT INTO Employee(EmpId, EmpCode,EmpName)
  VALUES
  (1, 'emp1','emp1'),
  (2, 'emp1','emp1'),
  (3, 'emp1','emp1');

select * from Employee
4) New Data Types
Data Type Data Type Use
Date The Date property returns a Date data type.
Time Returns values for any valid time of day between 00:00:00 and 23:59:59:9999999. It has a length of at least 8 positions and contains the time in hours,minutes, seconds and fractional seconds.
DateTime2 DateTime2 is an extension of the existing DATETIME type. It has a large date range and large default fractional precision. It has a length of at least 19 positions.
DateTimeOffSet Returns values for year, month, day, valid time of day between 00:00:00 and 23:59:59:9999999 and offset, in hours, from UTC. It has a length of at least 25 positions.
Hierarchyid The HierarchyId property is used to identify a position in a hierarchy.
Geography The SQL Server geography data type stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates
Geometry The Geometry property contains spatial data that represents information about the physical location and shape of geometric objects.
HierarchyId Data Type
   1: --Create Table Employee

   2: CREATE TABLE Employee

   3: (

   4: EmpId int,

   5: EmpBossId HIERARCHYID,

   6: --GetLevel --> returns the level of the current node in the hierarchy

   7: EmpLevel as EmpBossId.GetLevel() PERSISTED,

   8: EmpCode varchar(50),

   9: EmpName varchar(50)

  10: );

  11: Go

  12: -- Create Insert Store Procedure

  13: Alter PROCEDURE Employee_isp

  14:     @empid int,

  15:     @empbossid int,

  16:     @empcode varchar(50),

  17:     @empname varchar(50)

  18: AS

  19: BEGIN

  20: declare @hid HIERARCHYID,@empboss_hid HIERARCHYID,@last_hid HIERARCHYID

  21:  

  22: if @empbossid = 0 

  23: begin

  24:     set @hid = HIERARCHYID::GetRoot();

  25: end 

  26: else 

  27: begin

  28:   

  29:   SET @empboss_hid = (SELECT EmpBossId FROM Employee  WHERE empid = @empbossid);

  30:   SET @last_hid = (SELECT MAX(EmpBossId) FROM Employee WHERE EmpBossId.GetAncestor(1)= @empboss_hid);

  31:   SET @hid = @empboss_hid.GetDescendant(@last_hid, NULL);

  32: end

  33: INSERT INTO Employee(empid, EmpBossId, EmpCode, EmpName)

  34:             VALUES(@empid, @hid, @empcode, @empname);

  35: END

  36: GO

  37: --insert data

  38: --                     A1

  39: --                AL1           AR1

  40: --           AL1L     AL1R  AR1L   AR1R  

  41: --

  42: --

  43: EXEC Employee_isp @empid =  1, @empbossid = 0, @empcode = 'A1' ,@empname = 'A1';

  44: EXEC Employee_isp @empid =  2, @empbossid = 1, @empcode = 'AL1' ,@empname = 'AL1';

  45: EXEC Employee_isp @empid =  3, @empbossid = 1, @empcode = 'AR1' ,@empname = 'AR1';

  46: EXEC Employee_isp @empid =  4, @empbossid = 2, @empcode = 'AL1L' ,@empname = 'AL1L';

  47: EXEC Employee_isp @empid =  5, @empbossid = 2, @empcode = 'AL1R' ,@empname = 'AL1R';

  48: EXEC Employee_isp @empid =  6, @empbossid = 3, @empcode = 'AR1L' ,@empname = 'AR1L';

  49: EXEC Employee_isp @empid =  7, @empbossid = 3, @empcode = 'AR1R' ,@empname = 'AR1R';

Inserted Data Into Table 
HIERARCHYID 
Different Selection Criteria :
1) Find Employee As Per their Level means Grade 
   select * from Employee where Emplevel = 2
2) Get Child Node 
   SELECT Child.empid, Child.empname FROM Employee AS Parent JOIN Employee AS Child
          ON Parent.empid = 2 AND child.empbossid.IsDescendantOf(Parent.empbossid) = 1;
3) Get Parent Node
SELECT parent.empid, parent.empname
  FROM Employee AS Parent JOIN Employee AS Child
    ON child.empid = 4 AND child.empbossid.IsDescendantOf(Parent.empbossid) = 1;
more on HierarchyId Data Types refer:
http://amitpatriwala.wordpress.com/2009/10/23/hierarchyid-data-type/

5) Introduced New Functions
Function Name Function Use
SYSDATETIME Returns current date and time as DateTime2 value.
SYSUTCDATETIME Returns current date and time in UTC as DateTime2 value
SYSDATETIMEOFFSET Returns current date and time along with the system time zone as a DATETIMEOFFSET value
SWITCHOFFSET Adjusts an input DATETIMEOFFSET value to a specified time zone, while preserving the UTC value.

For example, the following code adjusts the current system datetimeoffset value to time zone GMT +05:00:

SELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), ‘-05:00′);

TODATETIMEOFFSET sets the time zone offset of an input date and time value
6) Support Large User Define Types [UDT]
Sql Server 2008 supports large UDT,large UDTs can now reach up to 2 GB in size.
 
Reference Sites: 
http://technet.microsoft.com/en-us/library/cc721270.aspx

October 2, 2009

URL rewriting in asp.net

what is URL rewriting ?

URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. When performing URL rewriting, typically the URL being requested is checked and, based on its value, the request is redirected to a different URL.

http://msdn.microsoft.com/en-us/library/ms972974.aspx 

why URL rewriting?

1) Make User Friendly and Secure URL

Example :  In your application, you create a page which display category information and it’s relevant category. At that time we normally passing a value via query string,

http://Site.com/category.aspx?categoryid=1. Any user play with URL, you can also do the URL Encryption. but sometime case is complex at that time it is not possible.

2) Make SEO Friendly URL

3) Usability & Maintainability

Use Of Browser file?

ASP.NET uses .browser files to determine the capabilities of the browser, and how to render markup to that browser.

Browser files are used to reduce the load of the page made by the view state by storing it in a server side session variable.

In particular Rewriting Module: Handling Post back with URL Rewriting.

what is ControlAdapter?

for more detail please check :

http://msdn.microsoft.com/en-us/library/system.web.ui.adapters.controladapter.aspx

Create demo project for URL Rewriting:

Step 1:

Create Web application with (Asp.net 2.0 with c#)

Step 2:

Put two button in the form (default.aspx)

Put Below code for Button1_Click Event :

Response.Redirect("Default.aspx?id=1");

Put Below code for Button2 _Click Event:

Response.Redirect("/urlrewriting/FirstSection/Default.html");

Step 3: Run Application

once you press Button2 it give Error page.

Step 4:

Create Class FormRewriterControlAdapter.cs

   1: using System;

   2: using System.Data;

   3: using System.Configuration;

   4: using System.Web;

   5: using System.Web.Security;

   6: using System.Web.UI;

   7: using System.Web.UI.WebControls;

   8: using System.Web.UI.WebControls.WebParts;

   9: using System.Web.UI.HtmlControls;

  10:  

  11: public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter

  12: {

  13:     protected override void Render(HtmlTextWriter writer)

  14:     {

  15:         base.Render(new RewriteFormHtmlTextWriter(writer));

  16:     }

  17: }

  18:  

  19: public class RewriteFormHtmlTextWriter : HtmlTextWriter

  20: {

  21:     public RewriteFormHtmlTextWriter(HtmlTextWriter writer)

  22:         : base(writer)

  23:     {

  24:         this.InnerWriter = writer.InnerWriter;

  25:     }

  26:  

  27:     public RewriteFormHtmlTextWriter(System.IO.TextWriter writer)

  28:         : base(writer)

  29:     {

  30:         base.InnerWriter = writer;

  31:     }

  32:  

  33:     public override void WriteAttribute(string name, string value, bool fEncode)

  34:     {

  35:         if (name == "action")

  36:         {

  37:             HttpContext Context = HttpContext.Current;

  38:             if (Context.Items["ActionAlreadyWritten"] == null)

  39:             {

  40:                 value = Context.Request.RawUrl;

  41:                 Context.Items["ActionAlreadyWritten"] = true;

  42:             }

  43:         }

  44:         base.WriteAttribute(name, value, fEncode);

  45:     }

  46: } 

 

Create Class MyHttpHandler.cs

   1: using System;

   2: using System.Data;

   3: using System.Configuration;

   4: using System.Web;

   5: using System.Web.Security;

   6: using System.Web.UI;

   7: using System.Web.UI.WebControls;

   8: using System.Web.UI.WebControls.WebParts;

   9: using System.Web.UI.HtmlControls;

  10:  

  11: public class MyHttpHandler : IHttpModule

  12:  

  13: {

  14:     public MyHttpHandler()

  15:     {

  16:         //

  17:         // TODO: Add constructor logic here

  18:         //

  19:     }

  20:  

  21:     #region IHttpModule Members

  22:  

  23:     public void Dispose()

  24:     {

  25:        

  26:     }

  27:  

  28:     public void Init(HttpApplication app)

  29:     {

  30:         app.BeginRequest += new EventHandler(Application_BeginRequest);

  31:     }

  32:  

  33:     private void Application_BeginRequest(object sender, EventArgs e)

  34:     {

  35:         System.Web.HttpApplication app = (System.Web.HttpApplication)sender;

  36:         string requestedUrl = app.Request.Path.ToLower();

  37:         string realUrl = GetRealUrl(requestedUrl);

  38:         if (!String.IsNullOrEmpty(realUrl))

  39:             app.Context.RewritePath(realUrl, false);

  40:     }

  41:  

  42:     private string GetRealUrl(string requestedUrl)

  43:     {

  44:         // Implement your own logic here

  45:         MyURL obj = new MyURL();

  46:         return obj.GetRealPath(requestedUrl);

  47:     } 

  48:     #endregion

  49: }

 

create Class MyURL.cs

   1:  

   2: using System;

   3: using System.Data;

   4: using System.Configuration;

   5: using System.Web;

   6: using System.Web.Security;

   7: using System.Web.UI;

   8: using System.Web.UI.WebControls;

   9: using System.Web.UI.WebControls.WebParts;

  10: using System.Web.UI.HtmlControls;

  11: using System.Collections.Generic;

  12:  

  13: /// <summary>

  14: /// Summary description for MyURL

  15: /// </summary>

  16: public class MyURL

  17: {

  18:     public MyURL()

  19:     {

  20:         //

  21:         // TODO: Add constructor logic here

  22:         //

  23:     }

  24:  

  25:     public string GetRealPath(string requestedUrl)

  26:     {

  27:         string path = "";

  28:         Dictionary<string, string> paths = GetPathsFromDatabase();

  29:         if (paths.ContainsKey(requestedUrl))

  30:             paths.TryGetValue(requestedUrl, out path);

  31:         return path;

  32:     }

  33:  

  34:     private static Dictionary<string, string> GetPathsFromDatabase()

  35:     {

  36:         Dictionary<string, string> paths = new Dictionary<string, string>();

  37:         paths.Add("/urlrewriting/FirstSection/Default.html".ToLower(), "/urlrewriting/Default.aspx?SectionID=1");

  38:         paths.Add("/urlrewriting/SecondSection/Default.aspx".ToLower(), "/urlrewriting/Default.aspx?SectionID=2");

  39:         paths.Add("/urlrewriting/FirstSection/Page1.aspx".ToLower(), "/urlrewriting/Default.aspx?SectionID=1&Item=1");

  40:         paths.Add("/urlrewriting/FirstSection/Page2.aspx".ToLower(), "/urlrewriting/Default.aspx?SectionID=1&Item=2");

  41:         paths.Add("/urlrewriting/SecondSection/Page1.aspx".ToLower(), "/urlrewriting/Default.aspx?SectionID=2&Item=1");

  42:         paths.Add("/urlrewriting/SecondSection/SubSection/AnotherOne/Page5.aspx".ToLower(), "/urlrewriting/Default.aspx?SectionID=2&Item=5");

  43:         paths.Add("/urlrewriting/Default.aspx".ToLower(), "/urlrewriting/Default.aspx");

  44:         return paths;

  45:     } 

  46: }

Register Http Handler in to Web.Config

   1: <system.web>

   2:         <httpModules>

   3:             <add name="MyHttpHandler" type="MyHttpHandler"/>

.Browser File

Add New .browser file from Add New Item.

   1: <browsers>

   2:     <browser id="NewBrowser" parentID="Mozilla">

   3:         <identification>

   4:             <userAgent match="Unique User Agent Regular Expression" />

   5:         </identification>

   6:  

   7:         <capture>

   8:             <userAgent match="NewBrowser (?'version'\d+\.\d+)" />

   9:         </capture>

  10:  

  11:         <capabilities>

  12:             <capability name="browser" value="My New Browser" />

  13:             <capability name="version" value="${version}" />

  14:         </capabilities>

  15:     </browser>

  16:  

  17:     <browser refID="Mozilla">

  18:         <capabilities>

  19:             <capability name="xml" value="true" />

  20:         </capabilities>

  21:     </browser>

  22: <!--FormRewrite Control Adapter-->

  23:     <browser refID="Default">

  24:         <controlAdapters>

  25:             <adapter controlType="System.Web.UI.HtmlControls.HtmlForm"

  26:                 adapterType="FormRewriterControlAdapter" />

  27:         </controlAdapters>

  28:     </browser>

  29: </browsers>

step 5: Run Application

Now Press Button 2:

http://localhost:2696/urlrewriting/FirstSection/Default.html and it is run.

 

Now made some change in to system. Remove browser file and click button2, after that made postback at that time above URL is change to original URL.

Reference Site :

For Detail Example :

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

 

Hope this help you.

Thnx

 

September 16, 2009

Crystal report with multiple sub report navigation problem in asp.net

Here I am explain the crystal report problem during the development.

I want to create Main report which having three sub reports. I create that report and call that report using asp.net but I have phase navigation problem.

Problem :

When Clicking the “Next” navigation button while on page 1 of Report Page 2 is appear, when clicking the “Next” navigation button while on page 2 , page 2 is repeated.

Solution :

Initially we write a Crystal report viewer code in to Page_Load event we move that code to Page_Init event and the Report navigation work.

Hope this help you.

thnx

August 28, 2009

PDF Viewer in asp.net

Filed under: Asp.Net 2.0, C#.net, dotnet — Tags: , — patriwala @ 1:49 pm

Here I am explaining how to create PDF Viewer in asp.net.

iPaper in asp.net

Steps:

1) create Class Library Project Here I am give name OnlinePdfViewer. Here I am using c#.net. Write below code in to file.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlinePdfViewer
{
    public class DisplayPdf : WebControl
    {
        private string _filepath;
        public string FilePath
        {
            get
            {
                return _filepath;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    _filepath = string.Empty;
                }
                else
                {
                    int tild = -1;
                    //check ~ symbol including in pdf path then remove
                    tild = value.IndexOf('~');
                    if (tild != -1)
                    {
                        _filepath = value.Substring((tild + 2)).Trim();
                    }
                    else
                    {
                        _filepath = value;
                    }
                }
            }
        }   

        protected override void RenderContents(HtmlTextWriter writer)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<iframe src=" + Convert.ToString(FilePath) + " ");
                //fix height and width
                sb.Append("width=800px height=500px");
                sb.Append("<View PDF: <a href=" + Convert.ToString(FilePath) + "</a></p> ");
                sb.Append("</iframe>");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.Write(Convert.ToString(sb));
                writer.RenderEndTag();
            }
            catch
            {
                //If any problem in the PDF at that time display below information
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.Write("PDF Control...");
                writer.RenderEndTag();
            }
        }
    }
}      

2) Run the project it generate dll –> OnlinePdfViewer.dll.

3) Create New Web Application give name – DemoPDFViewer.I have create application in asp.net with c#.

    Here I have create demo application In application User can upload PDF and View uploaded PDF in PDF viewer.

3.1) Add the Reference of OnlinePdfViewer.dll into Site.

3.2) Make PDF folder into Site.

3.3) Upload PDF Functionality

ASPX Code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="OnlinePdfViewer" Namespace="OnlinePdfViewer" TagPrefix="PdfViewer" %>
<!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>PDF View Online</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
            <table>
                <tr>
                    <td colspan="2" align="center" style="font-family: Verdana; font-size: larger">
                        Online PDF Viewer
                    </td>
                </tr>
                <tr>
                    <td>
                        Upload PDF File
                    </td>
                    <td>
                        <asp:FileUpload ID="fup" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblMsg" runat="server" ViewStateMode="Disabled" Font-Bold="true" ForeColor="Red"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button ID="btnView" Text="View PDF" runat="server" Visible="false" OnClick="btnView_Click" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" id="pnlPDFViewer" visible="false" runat="server">
                        <asp:HyperLink ID="HyperLink1" runat="server">Open PDF into New Page</asp:HyperLink>
                        <br />
                        <PdfViewer:DisplayPdf ID="displaypdf1" runat="server" BorderStyle="Inset" BorderWidth="2px"
                            Style="height: 500px;" Width="800px" />
                    </td>
                </tr>
            </table>
        </center>
    </div>
    </form>
</body>
</html>

CS Code:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string Uploadedfilename { get { return Convert.ToString(ViewState["filename"]); } set { ViewState["filename"] = value; } }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fup.HasFile)
        {
            string strFilePath = Server.MapPath("PDF") + "\\";
            Uploadedfilename = Convert.ToString(Guid.NewGuid()) + ".pdf";
            strFilePath = strFilePath + Uploadedfilename;
            fup.SaveAs(strFilePath);
            lblMsg.ForeColor = Color.Blue;
            lblMsg.Text = "PDF File Upload Successfully";
            btnView.Visible = true;
        }
        else
        {
            lblMsg.Text = "Please Upload PDF File";
        }
    }
    protected void btnView_Click(object sender, EventArgs e)
    {
        pnlPDFViewer.Visible = true;
        displaypdf1.FilePath = @"~/pdf/" + Uploadedfilename;
        HyperLink1.NavigateUrl = @"~/pdf/" + Uploadedfilename;
    }
}

4) compile code and run application.

 

thnx

July 13, 2009

Change Browser Setting In Flex Application

Filed under: Flex, Flex Applicaiton — Tags: , — patriwala @ 5:21 pm

I have used the Flex Application with IE. Now I have change Browser and make it Firefox.

There are two steps.

1) First Select Menu—> windows –> Preferences –> General  –> Web Browser…

After that you may able to change the browser.

 

2) Go to Command Prompt and type

-–> ftype http=”c:\Program Files\Mozilla Firefox\firefox.exe”

Reopen Flex Application.

Now run your application then browser is changed.

 

 

thnx

June 23, 2009

Calling Web service from Flex – Part 1

Filed under: Asp.Net 2.0, Flex — Tags: , , — patriwala @ 2:02 pm

Here I am Explain how to use Web Services in Flex Application.

Steps:

1) First we create web service in Asp.net with C#. create new Web method in Web service is GetName.

[WebMethod]
    public string GetName(string UserName)
    {
        return "WelCome  " + UserName;
    }

My web service name is WebServices.

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }
    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [WebMethod]
    public string GetName(string UserName) {
        return "WelCome  " + UserName;
    }
}

2) Open Flex Application.

3) Put below control in to application.

    3.1)  WebService (ID =MyWebService)

    3.2) Label for display Information

    3.3) TextArea (ID=txtUserName) – get value and pass value in to WebService

    3.4) Button (ID=btnSubmit) – Call Web service

    3.5) TextArea (ID=txtResult) – Display result from Web service

Application Page Info.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<!--Web Service Information
wsdl  URL of Web Service
fault  if any error loading web service
operation  method name in Webservices
request  pass the parameter to Webservices
*here I get the TextBox Value
-->
<mx:WebService id="MyWebService" wsdl="http://localhost:3549/ChangeWebConfigFile/WebService.asmx?WSDL"
    fault="mx.controls.Alert.show(event.fault.faultString)" >
    <mx:operation name="GetName">
        <mx:request>
        <UserName>{txtUserName.text}</UserName>
        </mx:request>
    </mx:operation>
</mx:WebService>
<mx:VBox>

    <mx:Label text="Enter User Name">
    </mx:Label>
    <mx:TextArea id="txtUserName" text="test">
    </mx:TextArea>

    <mx:Button id="btnSubmit" label="Submit.." click="checkUserName();">
    </mx:Button>
    <mx:TextArea id="txtResult"/>
</mx:VBox>
<mx:Script>
    <![CDATA[
      private function checkUserName():void
    {
        MyWebService.GetName.send();
        txtResult.text= MyWebService.GetName.lastResult;
    }
    ]]>
</mx:Script>
</mx:Application>

4) Run Flex Application.

 

image

 

 

thnx

Error #1085: The element type “p” must be terminated by the matching end-tag “” in Flex

Filed under: Flex — Tags: — patriwala @ 1:37 pm

I have got this Error when I used asp.net web services in FLEX. I found Solution which is mention below.

Steps:

1) Check the URL of your Web Services

    you can put direct URL of Web services here I am used URL is  http://localhost:3549/ChangeWebConfigFile/WebService.asmx and got Error.

2)

change in URL http://localhost:3549/ChangeWebConfigFile/WebService.asmx?WSDL and solve the Error.

thnx

December 3, 2008

Convert Generic List In To DataTable

Create simple asp.net application with C#. Add new class (GenericToDataTable).

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;

public class GenericToDataTable
{
/// <summary>
/// Default Constructor
/// </summary>
private GenericToDataTable()
{ }
/// <summary>
///
/// </summary>
/// <typeparam name=”T”>Custome Class </typeparam>
/// <param name=”lst”>List Of The Custome Class</param>
/// <returns> Return the class datatbl </returns>
public static DataTable ConvertTo<T>(IList<T> lst)
{
//create DataTable Structure
DataTable tbl = CreateTable<T>();
Type entType = typeof(T);

PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entType);
//get the list item and add into the list
foreach (T item in lst)
{
DataRow row = tbl.NewRow();
foreach (PropertyDescriptor prop in properties)
{
row[prop.Name] = prop.GetValue(item);
}
tbl.Rows.Add(row);
}

return tbl;
}

/// <summary>
///
/// </summary>
/// <typeparam name=”T”>Custome Class</typeparam>
/// <returns></returns>
public static DataTable CreateTable<T>()
{
//T –> ClassName
Type entType = typeof(T);
//set the datatable name as class name
DataTable tbl = new DataTable(entType.Name);
//get the property list
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entType);
foreach (PropertyDescriptor prop in properties)
{
//add property as column
tbl.Columns.Add(prop.Name, prop.PropertyType);
}
return tbl;
}
}

after add above class compile the code.

after compilation add new class into project (Class Name: clsUser).

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsUser
/// </summary>
public class clsUser
{
//create property userid
private int _UserId;
public int UserID
{
get { return _UserId; }
set { _UserId = value; }
}
//create property username
private string _UserName;
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
/// <summary>
/// Default Constructor
/// </summary>
public clsUser()
{ }

public clsUser(int userid,string username)
{
this.UserID = userid;
this.UserName = username;
}
}

After adding this class into project go to Default.aspx page in this page type below code on Page Load event.

//create generic list of class clsUser
System.Collections.Generic.List<clsUser> obj = new
System.Collections.Generic.List<clsUser>();
//add data into list
for (int i = 0; i < 10; i++)
{
obj.Add(new clsUser(i,”a”+i.ToString()));
}
//convert list to datatable
DataTable dt= GenericToDataTable.ConvertTo<clsUser>(obj);

now check the DataTable(dt).

thnx

October 11, 2008

Get Parameter List from StoreProcedure or Function in SqlServer 2005

–get all storeprocedure and function

SELECT * FROM INFORMATION_SCHEMA.PARAMETERS

–pass storeprocedure name or function name

–get the relavent columns ParameterName,DataType,Length,ParameterType

SELECT Parameter_name as ParameterName,Data_type as DataType,coalesce(Character_Maximum_Length,0) as Length,Parameter_Mode as ParameterType FROM INFORMATION_SCHEMA.PARAMETERS

WHERE SPECIFIC_NAME=’sp_InsertOrder’

Older Posts »

Blog at WordPress.com.