Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. protected void BtnID_Click(object sender, EventArgs e)
  2. {
  3. int id = Convert.ToInt32(TextBoxID.Text);
  4. try
  5. {
  6.  
  7. List<ASPWebApp.CottagesServiceReference.Cottages> cottages = ws.GetCottageInfoByID(id).ToList();
  8.  
  9. ListItem cottage = new ListItem(String.Join(".", cottages));
  10.  
  11. BulletedList1.Items.Add(cottage);
  12.  
  13. BulletedList1.DataSource = cottages;
  14. BulletedList1.DataBind();
  15.  
  16.  
  17. }
  18. catch (Exception a)
  19. {
  20. Console.WriteLine(a);
  21. }
  22. }
  23.  
  24. public List<Cottages> GetCottageInfoByID(int id)
  25. {
  26. List<Cottages> cottage = new List<Cottages>();
  27.  
  28. SqlConnection conn = new SqlConnection(dataSource);
  29.  
  30. string sqlQuerySelectCottageInfo = "SELECT Cottage_Name as 'Name', Cottage_Location as Location, No_Of_Rooms as Rooms, Description, Cost_Per_Night as Cost FROM dbo.Cottages where Cottage_ID = @id";
  31.  
  32. SqlCommand cmd = new SqlCommand(sqlQuerySelectCottageInfo);
  33. cmd.Parameters.AddWithValue("@id", id);
  34.  
  35. conn.Open();
  36.  
  37. cmd.Connection = conn;
  38.  
  39. SqlDataReader reader = cmd.ExecuteReader();
  40.  
  41.  
  42. while (reader.Read())
  43. {
  44. if (!reader.HasRows)
  45. {
  46. throw new Exception("No Cotteges Found");
  47. }
  48. else
  49. {
  50.  
  51. cottage.Add(new Cottages()
  52. {
  53. Name = (reader[("Name")].ToString()),
  54. Location = (reader[("Location")].ToString()),
  55. Rooms = Convert.ToInt32(reader[("Rooms")]),
  56. Cost = Convert.ToDecimal(reader[("Cost")]),
  57. Description = (reader[("Description")].ToString()),
  58.  
  59. });
  60.  
  61. }
  62.  
  63. }
  64.  
  65. reader.Close();
  66.  
  67. conn.Close();
  68.  
  69. return cottage;
  70. }
  71.  
  72. <td class="Column2" colspan="1">
  73. <asp:TextBox class="TxtID" ID="TextBoxID" runat="server" BorderColor="Gray" BorderStyle="Solid" BorderWidth="2px" CausesValidation="False"></asp:TextBox>
  74. <asp:Button class="BtnID" ID="BtnID" runat="server" Text="Search" OnClick="BtnID_Click" />
  75. <asp:BulletedList class="Bullets" ID="BulletedList1" runat="server">
  76. </asp:BulletedList>
  77. </td>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement