Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
  2. con.Open();
  3. SqlCommand cmd = new SqlCommand("sp_utmerge", con);
  4. cmd.CommandType = CommandType.StoredProcedure;
  5. cmd.Parameters.AddWithValue("@userId", Txt_Userid.Text);
  6. cmd.Parameters.AddWithValue("@username", Txt_Uname.Text);
  7. cmd.Parameters.AddWithValue("@designation", Txt_Design.Text);
  8. cmd.Parameters.AddWithValue("@dept", Txt_Dept.Text);
  9. cmd.Parameters.AddWithValue("@contact_no", Txt_Cntct.Text);
  10. cmd.Parameters.AddWithValue("@email", Txt_Email.Text);
  11. cmd.Parameters.AddWithValue("@address", Txt_Addrs.Text);
  12. cmd.Parameters.AddWithValue("@dob", Txt_DOB.Text);
  13. cmd.Parameters.AddWithValue("@password", Txt_Pwd.Text);
  14. cmd.ExecuteNonQuery();
  15. con.close();
  16.  
  17. ALTER PROCEDURE [dbo].[sp_utmerge]@userId nvarchar(10),@username nvarchar(50),@designation nvarchar(50),@dept nvarchar(20),@contact_no nvarchar(20),@email nvarchar(MAX),@address nvarchar(100),@dob varchar(20),@password nvarchar(20)
  18. AS
  19. BEGIN
  20. SET NOCOUNT ON;
  21. merge Teachermast as target
  22. using (select userId, username, designation, dept, contact_no, email, address, dob, password from UserMast where usertype = 3)
  23. as source(userId, username, designation, dept, contact_no, email, address, dob, password)
  24. on target.teacher_code = source.userId
  25. when not matched by target then
  26. insert (teacher_code, teacher_name, designation, dept_code, contact_no, email, address, dob, password)
  27. values (source.userId, source.username, source.designation, source.dept, source.contact_no, source.email, source.address, source.dob, source.password);
  28.  
  29. END
  30.  
  31. USE [ABC]
  32. GO
  33.  
  34. DECLARE @return_value int
  35.  
  36. EXEC @return_value = [dbo].[sp_utmerge]
  37. @userId = N'T0006',
  38. @username = N'abc',
  39. @designation = N'Teacher ',
  40. @dept = N'EIC',
  41. @contact_no = N'9632563256',
  42. @email = N'abc@yahoo.com',
  43. @address = N'97 xyz street',
  44. @dob = N'31/08/1990',
  45. @password = N'12345'
  46.  
  47. SELECT 'Return Value' = @return_value
  48.  
  49. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement