.NET Xpress

Microsoft Technology Xplicit

Archive for the ‘.NET’ Category

Excel and Exponential Value

Posted by anandkumar2004 on April 6, 2009

Recently I was working on MS Excel automation project, during development I was facing some serious problems like getting exponential value while reading a cell data such as 0.23485759606896689878794. Now the question is how to convert exponential value to the actual value?  The answer is

 

decimal originalVal = decimal.Parse(cellArray[2].Tostring(), System.Globalization.NumberStyles.Any);

 

Please be aware this kind of small issues can be a nightmare for you and your project.

 

 

Cheers

Anand

Posted in .NET | Leave a Comment »

Core Features of C# 2.0 – DEVCON 2006

Posted by anandkumar2004 on November 20, 2006

DEVCON 2006 is a great success , thanks to core and UG members .Here is my presentation and code sample of Core Features of C# 2.0

 

Core Features of C# 2.0 ( Presentation)

Demos

 

Note : Please rename Demos.doc to Demos.zip and then unzip it to walk through the sample code of  the presentation .

 

Cheers

Anand

 

Posted in .NET | Leave a Comment »

DevCon 2006

Posted by anandkumar2004 on October 26, 2006

Very good news for Hyderabad techies , Microsoft User Group Hyderabad (http://mugh.net/) will conduct DevCon2006 for developers and IT Pro in  the month of November  2006 . I will publish the detail shortly

 

Cheers

Anand

Posted in .NET | 2 Comments »

Just-My-Code

Posted by anandkumar2004 on October 20, 2006

Visual Studio 2005 debugger has a new feature called Just-My-Code for debugging the managed code .This is a very cool debugging enhancement helps to debug the code only written by you and ignore other code (non user code) such as system call or the code that is in the framework. The next question comes to mind is how debugger distinguishes user-code and non-user code?  The answer is debugger looks the code in three places that is  DBG files,PDB files and optimized code  lets say when you are executing  the application under debug mode  and  JMC is enable then the debugger displays and steps into the code other then

  • System Code or  Framework Code
  • Code that is optimized or
  • Does not have debugging symbols
  • The code marked through System.Diagnostics.DebuggerNonUserCodeAttribute attribute  by the developer

To enable  Just-My-Code option select Tools | Options | Debugging | General | Just My Code.This makes our debugging activity very simple but I recommend you to turn it off  I had few problems ( a kind of confuse) while debug complex code.

Posted in .NET | 2 Comments »

Hosting ADO.NET code in SQLCLR

Posted by anandkumar2004 on October 18, 2006

We have done very excitement stuffs in ADO.NET 1.0 now ADO.NET 2.0 has enhanced a lot in order to make our application more scalable and much more flexible ,one of the major enhancement in ADO.NET 2.0 is highly integration with SQL Server 2005 (YUKON) .YUKON ships with CLR to host managed code here I am illustrating how to host ADO.NET code in SQLCLR .

Have a look at the ADO.NET 1.0 code snippet

using System;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class MySample
{
public void MyConn()
{
SqlConnection connObj = new SqlConnection(“server=TestServer; database=Emp; user id=anand; password=$nand”);
connObj.Open();

SqlCommand cmdObj = new SqlCommand(“SELECT Name, Sal FROM Emptbl”, connObj);

SqlDataReader redObj = cmdObj.ExecuteReader();

while (redObj.Read())
{
// do your stuff}
}
}
}
}

Now lets try to host this code in SQLCLR for this you need to create a database project ( File | New|Project… select Database as project type) and click on SQL Server Project .Once you create the project it will prompts for server detail , specify the server name, access mode( Windows Authentication or SQL Authentication) and select the database you want to connect .After the above step you need to create managed stored procedure to do this select Project|Add New Item… and chose Stored Procedure , click on Add button to add the file to project below is the actual code

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcedure2()
{
SqlConnection connObj = new SqlConnection(“server=TestServer; database=Emp; user id=anand; password=$nand”);
connObj.Open();

SqlCommand cmdObj = new SqlCommand(“SELECT Name, Sal FROM Emptbl”, connObj);

SqlDataReader redObj = cmdObj.ExecuteReader();

while (redObj.Read())
{
// do your stuff}
}

}
};

Note: Set the permission to EXTERNAL_ACCESS (right-click on the project node,select Properties|Database tab, and then from the Permission Level combo-box, select External)

Now the next BIG thing is how to run this in SQL Server 2005. Visual Studio makes it trivial to deploy the assembly to SQL Server and take the appropriate steps to register each of the objects in the assembly with the server. After compile to code select Build | Deploy Solution it will connect to SQL Server send the assembly to the server and register it and then register the stored procedure that you added to the assembly.The final step it to press F5 and start execute the code even you can debug the T-SQL and managed code .

Posted in .NET | Leave a Comment »

Orcas – CTP available

Posted by anandkumar2004 on October 16, 2006

Orcas is the next generation development tool for VISTA,O12 and web app etc  click here to download  September CTP 

Posted in .NET | Leave a Comment »