home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / InfoPath.en-us / InfLR.cab / FL_CalltheExecuteScalarMethodofaDataComman_142625_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  2KB  |  56 lines

  1. <?xml version="1.0"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <Title>Call the ExecuteScalar Method of a SqlCommand</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Executes a SQL statement that returns a single value using the SqlCommand.ExecuteScalar method of an existing data command.</Description>
  8.       <Shortcut>adoExecScalar</Shortcut>
  9.     </Header>
  10.     <Snippet>
  11.       <References>
  12.         <Reference>
  13.           <Assembly>System.Data.dll</Assembly>
  14.         </Reference>
  15.         <Reference>
  16.           <Assembly>System.Xml.dll</Assembly>
  17.         </Reference>
  18.       </References>
  19.       <Imports>
  20.         <Import>
  21.           <Namespace>System.Data</Namespace>
  22.         </Import>
  23.         <Import>
  24.           <Namespace>System.Data.SqlClient</Namespace>
  25.         </Import>
  26.       </Imports>
  27.       <Declarations>
  28.         <Object>
  29.           <ID>conn</ID>
  30.           <Type>System.Data.SqlClient.SqlConnection</Type>
  31.           <ToolTip>Replace with an existing connection object.</ToolTip>
  32.           <Default>conn</Default>
  33.         </Object>
  34.         <Object>
  35.           <ID>cmd</ID>
  36.           <Type>System.Data.SqlClient.SqlCommand</Type>
  37.           <ToolTip>The name of an existing SqlCommand to execute</ToolTip>
  38.           <Default>cmd</Default>
  39.         </Object>
  40.       </Declarations>
  41.       <Code Language="VB" Kind="method body"><![CDATA[Dim result As Object
  42. Dim previousConnectionState As ConnectionState = $conn$.State
  43. Try
  44.     If $conn$.State = ConnectionState.Closed Then
  45.         $conn$.Open()
  46.     End If
  47.     result = $cmd$.ExecuteScalar()
  48. Finally
  49.     If previousConnectionState = ConnectionState.Closed Then
  50.         $conn$.Close()
  51.     End If
  52. End Try
  53. ]]></Code>
  54.     </Snippet>
  55.   </CodeSnippet>
  56. </CodeSnippets>