snippet zur DB Abfrage über einen Datareader.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Database2</Title>
<Shortcut>Database2</Shortcut>
<Description>Codeausschnitt für Datenbank</Description>
<Author>Nico Patitz</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>expression</ID>
<ToolTip>Ausnahmetyp</ToolTip>
<Function>SimpleTypeName(global::System.Exception)</Function>
</Literal>
<Literal>
<ID>funktionname</ID>
<ToolTip>Funktion, die Exeption geworfen hat</ToolTip>
<Default>var</Default>
</Literal>
<Literal>
<ID>con</ID>
<ToolTip>Bezeichner der Verbindung</ToolTip>
<Default>con</Default>
</Literal>
<Literal>
<ID>reader</ID>
<ToolTip>Bezeichner des Reader</ToolTip>
<Default>reader</Default>
</Literal>
<Literal>
<ID>command</ID>
<ToolTip>Bezeichner des Commandos</ToolTip>
<Default>command</Default>
</Literal>
<Literal>
<ID>constring</ID>
<ToolTip>ConnectionString Name aus App.Conf/Web.Conf</ToolTip>
<Default>CustConnectionString</Default>
</Literal>
<Literal>
<ID>sqlstring</ID>
<ToolTip>Sql statement</ToolTip>
<Default></Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[$selected$SqlConnection $con$ = new SqlConnection(ConfigurationManager.ConnectionStrings["$constring$"].ConnectionString);
SqlCommand $command$ = new SqlCommand("",$con$ );
$command$.CommandText = "$sqlstring$";
SqlDataReader $reader$=null;
try
{
$con$.Open();
$reader$= command.ExecuteReader();
while($reader$.Read())
{
}
}
catch(Exception ex)
{
//TODO: Exception-handling
}
finally
{
$con$.Close();
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Kommentare zum Snippet