Skip to content
Loading
.cs
  1. using System;  
  2. using System.Configuration;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.HtmlControls;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Xml.Linq;  
  12. using System.Data.SqlClient;  
  13. namespace TAClaim  
  14. {  
  15. public partial class ITBanner : System.Web.UI.Page  
  16. {  
  17. string connStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;  
  18. SqlCommand com;  
  19. string str;  
  20. SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=Employee;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;");  
  21. protected void Page_Load(object sender, EventArgs e)  
  22. {  
  23. }  
  24. protected void Button1_Click(object sender, EventArgs e)  
  25. {  
  26. clear();  
  27. idcheck();  
  28. SqlConnection con = new SqlConnection(connStr);  
  29. con.Open();  
  30. str = "select * from emp_mast1 where empid='" + TextBox1.Text.Trim() + "'";  
  31. com = new SqlCommand(str, con);  
  32. SqlDataReader reader = com.ExecuteReader();  
  33. if (reader.Read())  
  34. {  
  35. TextBox2.Text = reader["firstname"].ToString();  
  36. TextBox3.Text = reader["lastname"].ToString();  
  37. TextBox4.Text = reader["designation"].ToString();  
  38. TextBox6.Text = reader["department"].ToString();  
  39. TextBox8.Text = reader["mobile"].ToString();  
  40. TextBox10.Text = reader["level"].ToString();  
  41. reader.Close();  
  42. con.Close();  
  43. }  
  44. }  
  45. public void idcheck()  
  46. {  
  47. SqlConnection con = new SqlConnection(connStr);  
  48. con.Open();  
  49. str = "select count(*)from emp_mast1 where empid='" + TextBox1.Text + "'";  
  50. com = new SqlCommand(str, con);  
  51. int count = Convert.ToInt32(com.ExecuteScalar());  
  52. if (count > 0)  
  53. {  
  54. lbl1.Text = "Id Does Exist";  
  55. }  
  56. else  
  57. {  
  58. lbl1.Text = "Id Does not Exist";  
  59. }  
  60. }  
  61. void clear()  
  62. {  
  63. TextBox2.Text = "";  
  64. TextBox3.Text = "";  
  65. TextBox4.Text = "";  
  66. TextBox5.Text = "";  
  67. TextBox6.Text = "";  
  68. TextBox7.Text = "";  
  69. TextBox8.Text = "";  
  70. TextBox9.Text = "";  
  71. TextBox10.Text = "";  
  72. TextBox11.Text = "";  
  73. }  
  74. protected void btnSave_Click(object sender, EventArgs e)  
  75. {  
  76. SqlCommand cmd = new SqlCommand("insert into registration(empid,firstname,lastname,designation,department,mobile,Basic_Pay,Tour_Comm_Dt,Tour_No,Level,Advance_from_Proj,) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox6.Text + "','" + TextBox8.Text + "','" + TextBox7.Text + "','" + TextBox5.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "')", con);  
  77. cmd.CommandType = CommandType.Text;  
  78. SqlDataAdapter sda = new SqlDataAdapter("Select * from registration", con);  
  79. DataTable dt = new DataTable();  
  80. sda.Fill(dt);  
  81. int i = dt.Rows.Count;  
  82. string cnt = Convert.ToString(i + 1);  
  83. try  
  84. {  
  85. con.Open();  
  86. cmd.ExecuteNonQuery();  
  87. Literal1.Text = "Generate successfully";  
  88. con.Close();  
  89. clear();  
  90. }  
  91. catch (Exception ex)  
  92. {  
  93. Literal1.Text = ex.Message;  
  94. }  
  95. }  
  96. }  
tabale structure:-
  1. CREATE TABLE [dbo].[TA] (  
  2. [TAId] INT IDENTITY (1, 1) NOT NULL,  
  3. [empid] NCHAR (10) NULL,  
  4. [firstname] VARCHAR (50) NULL,  
  5. [lastname] VARCHAR (50) NULL,  
  6. [designation] VARCHAR (50) NULL,  
  7. [department] VARCHAR (50) NULL,  
  8. [mobile] NCHAR (10) NULL,  
  9. [level] NCHAR (10) NULL,  
  10. [ Basic_Pay] NCHAR (10) NULL,  
  11. [ Tour_Comm_Dt] NCHAR (10) NULL,  
  12. [ Tour_No] NCHAR (10) NULL,  
  13. [Advance_from_Proj] NCHAR (10) NULL,  
  14. PRIMARY KEY CLUSTERED ([Id] ASC)  
  15. );  
  16. }  
0