Feeds:
Posts
Comments

Archive for February, 2007

       Hi, You all have observe that when we use validation summary, it takes some extra space as shown below.

Fig – (1) Extra space in validation summary.

       You can remove extra space shown in fig – (1) by using style sheet. Below is the code.

<style type=”text/css”>
    UL
   {
          margin: 0 ;
          padding:5px;
   }
</style>

Fig – (2) CSS to remove extra space.

Happy Programming.

Read Full Post »

              I have to work with google map in my current project. I search on net for the documentation of the API. Google has given really good exaples how to use that. However, everything is done using javascript. I was searching for the control that allow me to do all this at code behind. I found really good control at

             http://be.sys-con.com/read/171162_1.htm

          I have modified it according to my requirement.  If you have any question you can ask me.

Happy Programming.

Read Full Post »

         Few days ago, in my blog(https://chiragrdarji.wordpress.com/2007/02/19/split-function-in-sql/)  I mentioned how to pass and use multiple values in single parameter in SP. I have mentioned that you can use XML format to do the same. Let me show you how to do that.

         Cionsider that you have to delete 5 rows from table and you have value of primary key for those 5 records. You have to prepare the XML document for these 5 IDs and pass it as a parameter to SP. Below is the functiion that generates XML.

       I have passed 5 IDs as coma seperated string in “Value”, and NodeName as parameters. I will Explain NodeName later.

public static string GetOpenXMLFormat(string Value,string NodeName)
{
            string strReturnVAlue = string.Empty; 
            // Create Root node.
             strReturnVAlue = “<Root>”

            if (Value.Length > 0)
            {
                  string[] strTemp = Value.Split(new string[] {“,”}, 
                                                          StringSplitOptions.RemoveEmptyEntries);

                  for (int i = 0; i < strTemp.Length; i++)
                 {
                       strReturnVAlue += “<” + NodeName + “IDS ” + NodeName + “ID ='”
                                                                + strTemp[i] + “‘/>”

                  }
             }
            strReturnVAlue += “</Root>”
            return strReturnVAlue;
}

Fig – (1) C# code generate XML document.

 

           Lets call above function GetOpenXMLFormat(“1,2,3,4,5” , “Emp”). This will generate XML file as shown below.

<Root>
         <EmpIDS EmpID = 1/>
         <EmpIDS EmpID = 2/>
         <EmpIDS EmpID = 3/>
         <EmpIDS EmpID = 4/>
         <EmpIDS EmpID = 5/>
</Root>

Fig – (2) Generated XML strig.

      Consider that we pass this parameter “@EmpIDS” to any SP. Below is the code that shows how to read this parameter in SP.

 

DELARE @EmpID int

DECLARE @docHandle int

EXEC sp_xml_preparedocument @docHandle OUTPUT, “@EmpIDS

SELECT * Into #TempEntities FROM
OPENXML(@docHandle, N’/Root/IDS’,1) WITH (EmpID int)

DECLARE TempCursor CURSOR FOR

SELECT SubGroupID, TrainingModuleID FROM #TempEntities

OPEN TempCursor

/* For each row in cursor*/
FETCH NEXT FROM TempCursor INTO @EmpID

/* Loop through cursor for remaining GroupID */
WHILE @@FETCH_STATUS = 0
BEGIN

      // Wirte a code to do desire operation

END

 

Fig – (3) Ream XML string parameter in SP.

         You can pass more than one attribute in XML parameter and read it. Below is the sample for 2 values 

OPENXML(@docHandle, N’/Root/IDS’,1) WITH (SubGroupID int ‘@SubGroupID’, TrainingModuleID int ‘@TrainingModuleID’)

Fig – (3)  Read values of 2 parameters

Happy programing.

Read Full Post »

         I have sotnet 1.1 and 2.0 both are installed on my machine.  When I create new asp.net web project in vs 2003 and tried to run it, it gives an error “unable to start debugging on server.”, the call stack shows an error mentioned in title. This is the case for all VS 2003 projects.

    The solution is you need to select appropriate version of CLR in IIS. Go to
Start –> Run –> type “inetmgr” and press ok. It opens IIS. Select appropriate version of IIS as shown in fig.

Fig-(1) Set CLR Version.

          Select version 1.1.4322 for VS 2003 project and 2.0.50727 for VS 2005 projects.

Happy Programming.

Read Full Post »

Split function in SQL

          I was working at home and extending a gridview control with some extra features I required. I have added one column with checkbox for multiple delete. To delete multiple records I need to pass either multiple ID to SP and delete all or can pass each ID one by one to SP.

        I passed all ID as coma separated string to SP.  I used split function to split the coma separated ID, so that I can use those ID in inner query. For example

DELETE FROM TableName WHERE ID IN (SELECT dbo.fun_Split(@AllID, ‘,’ ))

Here you have to pass string value and separator as a parameter. In my case, I have used “,” as seperator. Below is the function,

Create function fun_Split (@String nvarchar(4000), @Delimiter char(1))
Returns @Results Table (Items nvarchar(4000))
As

Begin
         Declare @Index int
         Declare @Slice nvarchar(4000)
         Select @Index = 1
        If @String Is NULL
                 Return
        While @Index != 0
        Begin
               Select @Index = CharIndex(@Delimiter, @String)
               If (@Index != 0)
                      Select @Slice = left(@String, @Index – 1)
               else
                     Select @Slice = @String

               Insert into @Results(Items) Values (@Slice)
               Select @String = right(@String, Len(@String) – @Index)
               If Len(@String) = 0
                     break
       End
       Return
End

Fig -(1) Split function SQL.

             There is another way to do the same. You can use open XML format to pass more than one parameters to SP. I will explain that in my next blog.

Happy Programing.

Read Full Post »

        I was serching for good material to learn cotnet 3.0. I found the good link which allows to download PPT file. Below is the link,

        http://www.dotnet-university.com/

Read Full Post »

            As we all knows .NET support side by side execution of multiple versions of component. In most cases, updating a component is simple.However, even in the .NET world, it is possible to break assembly binding when you update a component.  One achieve that control is the publisher policy assembly.

What is a publisher policy assembly?

                 A publisher policy assembly is an assembly that configures the policy to be used when the .NET runtime binds to an assembly. The publisher policy assembly is installed into the GAC and is named using the following naming convention:

                policy.major_ver.minor_ver.assembly.dll

                    The major_ver and minor_ver refer to the major and minor version of the old version of the assembly. Therefore, if you are updating version 1.0 of Website.dll to version 2.0, and you want all existing applications to bind to the new version, the publisher policy assembly name would be:

                 policy.1.0.website.dll

After this publisher policy assembly is installed into the GAC, any application that references version 1.0 of Website.dll will bind to version 2.0 of Website.dll instead. At this point, you might be asking how the .NET runtime knows to bind to version 2.0 of Website.dll when it sees the publisher policy assembly in the GAC. The answer lies in the publisher policy file, an XML configuration file that is used to create the publisher policy assembly.

                       The publisher policy file contains the information necessary to redirect the binding from one version of an assembly to a new version. After you’ve created the publisher policy file, you use the .NET Assembly Linker utility (Al.exe) to create the publisher policy assembly.

                        Here is an example of a publisher policy file that redirects any reference to version 1.0 of Website.dll to version 2.0. The public key token can be obtained by looking at the properties of the assembly currently installed in the GAC.

<configuration>
<runtime>
 <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>      <dependentAssembly>
<assemblyIdentity name=”website” publicKeyToken=”18517ea673f8584b” culture=”neutral” />
<bindingRedirect oldVersion=”1.0.0.0″ newVersion=”2.0.0.0″/> </dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

 

The entire process

Scenario: You want to ensure that any ASP.NET application currently referencing version 1.0 of your server control uses version 2.0 instead after the updated version is installed. You don’t want anyone to have to modify configuration files for this to happen. You have wisely determined that a publisher policy assembly is the way to go.
This is how you should proceed.

1. Change the version and recompile.    The first step is to create the new version of your component. After you’ve done that, you will need to modify the version number in the AssemblyInfo file for your component.

2.Create the publisher policy file.Create the publisher policy file for the assembly using the format shown above.

3.Use Assembly Linker (Al.exe) to create the publisher policy assembly. The Assembly Linker is included with the .NET Framework SDK. To create the publisher policy assembly that redirects a binding from version 1.0 of Website.dll to version 2.0 using a publisher policy file called website.config, run the following command:

al /link:website.config /out:policy.1.0.website.dll /keyfile:c:\keyfile.snk

This command will create a new assembly called policy.1.0.website.dll. This naming convention is important, as indicated in the “What Is a Publisher Policy Assembly?” section.

4.Install the publisher policy assembly into the Global Assembly Cache. The publisher policy assembly is installed into the GAC. It will be used by the .NET runtime when any application attempts to bind to version 1.0 of the Website.dll, and it will force the application to bind to the new version automatically.

5.Install the new version into the Global Assembly Cache. Install the new version of the component into the GAC. After the new version has been installed, the old version can be safely removed.

6.Restart Microsoft Internet Information Services (IIS). The final step is to restart IIS. This is necessary because of the way the .NET runtime binds to an assembly. If the .NET runtime has already bound to a specific assembly, it will reuse that binding. Therefore, for the binding redirect to the new assembly to work, you must restart the worker process.

                  After completing these steps, any application that was built with a reference to version 1.0 of Website.dll will automatically use version 2.0. Publisher policy assemblies offer a convenient way to ensure that developers have full control over assembly binding. As you’ve seen in this article, if your goal is to force existing applications to use a new version of your component, a publisher policy assembly provides you with the confidence that applications will always use the version you expect them to use without having to alter any configuration files or rely on manual changes by a server administrator.

 

You can find detail information at,

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B891030

Happy Programming.

Read Full Post »

Older Posts »