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_CalltheExecuteReaderMethodofaDataComman_142624_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  2KB  |  68 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 ExecuteReader Method of a SqlCommand</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Fetches data from a database using the SqlCommand.ExecuteReader method of an existing data command.</Description>
  8.       <Shortcut>adoExecReader</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.         <Literal>
  29.           <ID>ProcessSprocResult</ID>
  30.           <Type>String</Type>
  31.           <ToolTip>Replace with your code to process the result of the DataReader.</ToolTip>
  32.           <Default>Console.WriteLine(reader.GetValue(0))</Default>
  33.         </Literal>
  34.         <Object>
  35.           <ID>conn</ID>
  36.           <Type>SqlConnection</Type>
  37.           <ToolTip>Replace with an existing connection object.</ToolTip>
  38.           <Default>conn</Default>
  39.         </Object>
  40.         <Object>
  41.           <ID>cmd</ID>
  42.           <Type>SqlCommand</Type>
  43.           <ToolTip>Replace with a SqlCommand to call ExecuteReader on.</ToolTip>
  44.           <Default>cmd</Default>
  45.         </Object>
  46.       </Declarations>
  47.       <Code Language="VB" Kind="method body"><![CDATA[Dim reader As SqlDataReader
  48. Dim previousConnectionState As ConnectionState = $conn$.State
  49. Try
  50. If $conn$.State = ConnectionState.Closed Then
  51.     $conn$.Open()
  52. End If
  53. reader = $cmd$.ExecuteReader()
  54. Using reader
  55.     While reader.Read
  56.         ' Process SprocResults datareader here.
  57.         $ProcessSprocResult$
  58.     End While
  59. End Using
  60. Finally
  61.     If previousConnectionState = ConnectionState.Closed Then
  62.         $conn$.Close()
  63.     End If
  64. End Try
  65. ]]></Code>
  66.     </Snippet>
  67.   </CodeSnippet>
  68. </CodeSnippets>