void ExecuteReaderDemo ( string query, string connString ) {
SqlConnection myConn = new SqlConnection ( connString );
SqlCommand myCmd = new SqlCommand ( query, myConn );
myConn.Open ( );
// bind a datalist to the reader
myList.DataSource = myCmd.ExecuteReader ( CommandBehavior.CloseConnection );
myList.DataBind ( );
myConn.Close ( );
}
Public Sub ExecuteReaderDemo ( query As String, connString As String )
Dim myConn As New SqlConnection ( connString )
Dim myCmd As New SqlCommand ( query, myConn )
myConn.Open ( )
' bind a datalist to the reader
myList.DataSource = myCmd.ExecuteReader ( CommandBehavior.CloseConnection )
myList.DataBind ( )
myConn.Close ( )
End Sub |