Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. this is aspx.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Data.SqlClient;
  10.  
  11.  
  12. public partial class phoneLostData : System.Web.UI.Page
  13. {
  14.  
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17.  
  18. Button b1 = sender as Button;
  19.  
  20. try
  21. {
  22. string dbAddress = @"Data Source=.SQLEXPRESS;AttachDbFilename=D:mcasem5sem5ProjectApp_DataDatabase.mdf;Integrated Security=True;User Instance=True; MultipleActiveResultSets=True;";
  23.  
  24. SqlConnection myCon = new SqlConnection(dbAddress);
  25. myCon.Open();
  26.  
  27. string q1 = "select complainerName,status from lostPhnFir";
  28.  
  29. SqlCommand myCmd = new SqlCommand(q1, myCon);
  30.  
  31. SqlDataReader readIt = myCmd.ExecuteReader();
  32.  
  33.  
  34.  
  35. while (readIt.Read())
  36. {
  37. // Response.Write("alert('hi')");
  38. if (readIt["complainerName"].Equals("abc") && readIt["status"].Equals("Checked"))
  39. {
  40. b1.Text = "Checked";
  41.  
  42. b1.Enabled = false;
  43.  
  44. }
  45. }
  46.  
  47. readIt.Close();
  48.  
  49. myCon.Close();
  50.  
  51.  
  52. }
  53. catch (Exception ex)
  54. {
  55. Response.Write(ex.Message);
  56. }
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. public void Button1(object sender, EventArgs e)
  65. {
  66. Button b1 = sender as Button; // I want to use this b1 to page_load
  67.  
  68. string dbAddress = @"Data Source=.SQLEXPRESS;AttachDbFilename=D:mcasem5sem5ProjectApp_DataDatabase.mdf;Integrated Security=True;User Instance=True; MultipleActiveResultSets=True;";
  69.  
  70. SqlConnection myCon = new SqlConnection(dbAddress);
  71. myCon.Open();
  72.  
  73. string q1 = "select complainerName from lostPhnFir";
  74. int flag = 0;
  75. SqlCommand myCmd = new SqlCommand(q1, myCon);
  76.  
  77. SqlDataReader readIt = myCmd.ExecuteReader();
  78.  
  79. if (b1.ID == "btnFIRLodge")
  80. {
  81. b1.Text = "Checked";
  82. b1.Enabled = false;
  83. flag = 1;
  84. }
  85.  
  86. if (flag == 1)
  87. {
  88. string status1 = "Checked";
  89. string s1 = "abc";
  90. string sql = "update lostPhnFir set status='" + status1 + "' where complainerName='" + s1 + "'";
  91. SqlCommand myCmd2 = new SqlCommand(sql, myCon);
  92. myCmd2.ExecuteNonQuery();
  93. }
  94. }
  95.  
  96. //this is aspx.
  97.  
  98. <asp:TemplateField HeaderText="FIR Lodged" ShowHeader="False">
  99. <ItemTemplate>
  100. <asp:Button ID="btnFIRLodge" runat="server"
  101. Text="Send Message" onclick="Button1"></asp:Button>
  102. </ItemTemplate>
  103. </asp:TemplateField>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement