Sunday, February 26, 2012

Generate Code Snippet With C# How?


 In this content I will talk about how to make a value little. Visible Facilities allows designers to preserve thoughts of value which can be loaded at a later time. This will preserve on retyping prevents of value that are used often. I also discover it very useful when I have to demonstrate value during demonstrations. Instead of entering everything stay, I discover it far simpler to simply add the value prevent by prevent using value thoughts.



Fallow the steps to create a code snippet using Visual Studio 2010.

CodeSnpt1.gif

Default Blank XML:
CodeSnpt2.gif

Default snippet generated XML tags:

CodeSnpt3.gif

Modified XML tags.

Add the SQL Connection Code to ![CDATA[]]
xml version="1.0" encoding="utf-8" ?><CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">  <Header>
    <
Title>SqlInsertTitle>    <Author>RavindraAuthor>    <Shortcut>SqlInsShortcut>    <Description>Sql ConnectionDescription>    <SnippetTypes>
      <
SnippetType>SurroundsWithSnippetType>      <SnippetType>ExpansionSnippetType>    SnippetTypes>
 
Header>
  <
Snippet>
    <
Declarations>
      <
Literal>
        <
ID>messageID>        <Default>my functionDefault>      Literal>
   
Declarations>
    <
Code Language="CSharp">                 SqlConnection con = new SqlConnection();
            try
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "";
                cmd.Parameters.AddWithValue("", "");
                cmd.Parameters.AddWithValue("", "");
                cmd.Parameters.AddWithValue("", "");
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                 throw;
            }
            finally
            {
                con.Close();
            }
]]>
   
Code>
 
Snippet>
CodeSnippet>

Snippet IntelliSense

CodeSnpt4.gif

Snippet generated C# code

CodeSnpt5.gif
 


SPONSORS:

No comments:

Post a Comment