Guest User

Untitled

a guest
Nov 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.SqlClient;
  6. using System.Configuration;
  7. using System.Data;
  8.  
  9. namespace WebApplication11
  10. {
  11. public class DataLayer
  12. {
  13. SqlConnection Con;
  14. string S_Con;
  15. public DataLayer()
  16. {
  17. connection();
  18. }
  19. private void connection()
  20. {
  21. S_Con = ConfigurationManager.ConnectionStrings["Db"].ConnectionString;
  22. Con = new SqlConnection(S_Con);
  23. if (Con.State == System.Data.ConnectionState.Open)
  24. {
  25. Con.Close();
  26. }
  27. Con.Open();
  28. }
  29. public List<Student> GetStudentList(int id = 0)
  30. {
  31. try
  32. {
  33. SqlCommand cmd = new SqlCommand("sp_StJal", Con);
  34. cmd.CommandType = CommandType.StoredProcedure;
  35. cmd.Parameters.Add("@ProcId", 1);
  36. if (id != 0)
  37. {
  38. cmd.Parameters.Add("@ID", id); }
  39. SqlDataReader rdr = cmd.ExecuteReader();
  40. List<Student> mlist = new List<Student>();
  41. while (rdr.Read())
  42. {
  43. Student ob = new Student();
  44. ob.ID = Convert.ToInt32(rdr["ID"]);
  45. ob.Name = rdr["Name"].ToString();
  46. ob.Age = Convert.ToInt32(rdr["Age"]);
  47. ob.Email = rdr["Email"].ToString();
  48. mlist.Add(ob);
  49. }
  50. return mlist;
  51. }
  52.  
  53.  
  54. catch (Exception E)
  55. {
  56. return null;
  57. }
  58. }
  59. public bool AddStudent(Student ob)
  60. {
  61. SqlCommand cmd = new SqlCommand("sp_StJal", Con);
  62. cmd.CommandType = CommandType.StoredProcedure;
  63. cmd.Parameters.Add("@Procid", 2);
  64. cmd.Parameters.Add("@Name", ob.Name);
  65. cmd.Parameters.Add("@Age", ob.Age);
  66. cmd.Parameters.Add("@Email", ob.Email);
  67. cmd.ExecuteNonQuery();
  68. return true;
  69. }
  70. }
  71. }
Add Comment
Please, Sign In to add comment