Tuesday, October 21, 2014

Retrieving Data Using a DataReader

Posted by Unknown  |  No comments


 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  

 Retrieving Data Using a DataReader  
 ----------------------------------  
 c#  
 ----  
 static void HasRows(SqlConnection connection)  
 {  
   using (connection)  
   {  
     SqlCommand command = new SqlCommand(  
      "SELECT CategoryID, CategoryName FROM Categories;",  
      connection);  
     connection.Open();  
     SqlDataReader reader = command.ExecuteReader();  
     if (reader.HasRows)  
     {  
       while (reader.Read())  
       {  
         Console.WriteLine("{0}\t{1}", reader.GetInt32(0),  
           reader.GetString(1));  
       }  
     }  
     else  
     {  
       Console.WriteLine("No rows found.");  
     }  
     reader.Close();  
   }  
 }  
 vb  
 ---  
 Private Sub HasRows(ByVal connection As SqlConnection)  
   Using connection  
     Dim command As SqlCommand = New SqlCommand( _  
      "SELECT CategoryID, CategoryName FROM Categories;", _  
      connection)  
     connection.Open()  
     Dim reader As SqlDataReader = command.ExecuteReader()  
     If reader.HasRows Then   
       Do While reader.Read()  
         Console.WriteLine(reader.GetInt32(0) _  
          & vbTab & reader.GetString(1))  
       Loop   
     Else  
       Console.WriteLine("No rows found.")  
     End If  
     reader.Close()  
   End Using   
 End Sub  

 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  


7:34 AM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top