Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

Visual Studio.NET 2005 comes with many cool features and one of them is Code Snippet Manager. Remember all the time writing boring code well, now you can make use of the Snippet Manager and hence paste the code in seconds.

All you need to do is to [YourSnippetFile].snippet file to the My Code Snippets folder and that's it. Here is one of my Snippet File which is use to create a BindData method which fills the dataset and return it to the client.

<?xml version="1.0"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/
                            2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Bind Data from DataSet</Title>
    </Header>
    <Snippet>
      <References>
        <Reference>
          <Assembly>System.dll</Assembly>
        </Reference>
      </References>
      <Imports>
        <Import>
          <Namespace>System.Data.SqlClient</Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal>
          <ID>METHOD</ID>
          <Default>BindData()</Default>
         </Literal>
        <Literal>
          <ID>SQLCONNECTION</ID>
          <Default>myConnection</Default>
        </Literal>
        <Literal>
          <ID>CONNECTIONSTRING</ID>
          <Default>ConnectionString</Default>
        </Literal>
        <Literal>
          <ID>ADAPTER</ID>
          <Default>ad</Default>
        </Literal>
        <Literal>
          <ID>QUERY</ID>
          <Default>query</Default>
        </Literal>
        <Literal>
          <ID>QUERYTEXT</ID>
          <Default>SELECT * FROM Categories</Default>
        </Literal>
        <Literal>
          <ID>DATASET</ID>
          <Default>ds</Default>
        </Literal>
        <Literal>
          <ID>TABLENAME</ID>
          <Default>Categories</Default>
        </Literal>
        
      </Declarations>
      <Code Language="csharp">
        <![CDATA[
        
      
private DataSet $METHOD$
   {
      
// make the query 
      
string $QUERY$ = "$QUERYTEXT$";
      SqlConnection $SQLCONNECTION$ = 
new SqlConnection($CONNECTIONSTRING$);  
      SqlDataAdapter $ADAPTER$ = 
new SqlDataAdapter($QUERY$,$SQLCONNECTION$); 
      DataSet $DATASET$ = 
new DataSet(); 
      $ADAPTER$.Fill($DATASET$,"$TABLENAME$"); 
      
return $DATASET$; 
      
   }
 ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

You will get your snippet in the intellisense of Visual Studio.NET 2005:

 And the code generated for the Snippet will be:

Pretty cool!

powered by IMHO

 

Posted on Sunday, November 27, 2005 12:16 AM | Back to top


Comments on this post: Code Snippet Manager in Visual Studio.NET 2005

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net