Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Iam not able to retrieve completely the data from sql?
  2. public string getString()
  3. {
  4.  
  5.   con.ConnectionString = ConnString;
  6.   con.Open();
  7.   string sp = "select top 3 hotelid from hotel order by NEWID()";
  8.   SqlCommand cmd = new SqlCommand(sp, con);
  9.  
  10.   SqlDataAdapter sa = new SqlDataAdapter(cmd);
  11.   cmd.ExecuteNonQuery();
  12.   reader = cmd.ExecuteReader();
  13.   while (reader.Read()) //Call Read to move to next record returned by SQL //OR call --While(reader.Read())
  14.   {
  15.     det  = reader[0].ToString();
  16.  
  17.   }
  18.   reader.Close();
  19.   con.Close();
  20.   return det;
  21. }
  22.        
  23. det += reader[0].ToString();
  24.        
  25. public List<string> getString()
  26. {
  27.   ...
  28.   List<string> ret = new List<string>;
  29.   while (reader.Read())
  30.     ret.Add(reader[0].ToString());
  31.   ...
  32.   return ret;
  33. }