Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.SqlClient;
  7.  
  8. namespace DatabaseActions
  9. {
  10. class Program
  11. {
  12. public static void AddUser(string firstname, string lastname, string username, string password, string password2, string email, string location, string birthday, string gender)
  13. {
  14. string connectionstring = @"Data Source=(localdb)\MSSQLLocalDB;initial catalog=GedgetsDB";
  15.  
  16. SqlConnection connection = new SqlConnection(connectionstring);
  17.  
  18. connection.Open();
  19. string insert1 = "INSERT INTO TBL_Users(FirstName, LastName, UserName, Password, Password2, Email, Location, Birthday, Gender)";
  20. string insert2 = "VALUES ('" + firstname + "' , '" + lastname + "' , '" + username + "' , '" + password + "' , '" + password2 + "' , '" + email + "' , '" + location + "' , '" + birthday + "' , '" + gender+"')";
  21. string Insertcommandtext = insert1 + insert2;
  22.  
  23. SqlCommand command = new SqlCommand(Insertcommandtext, connection);
  24. command.ExecuteNonQuery();
  25. connection.Close();
  26. }
  27. static void Main(string[] args)
  28. {
  29. Console.Write("Enter firstname: ");
  30. string firstname = Console.ReadLine();
  31. Console.Write("Enter lastname: ");
  32. string lastname = Console.ReadLine();
  33. Console.Write("Enter username: ");
  34. string username = Console.ReadLine();
  35. Console.Write("Enter password: ");
  36. string password = Console.ReadLine();
  37. Console.Write("Enter password2: ");
  38. string password2 = Console.ReadLine();
  39. Console.Write("Enter email: ");
  40. string email = Console.ReadLine();
  41. Console.Write("Enter location: ");
  42. string location = Console.ReadLine();
  43. Console.Write("Enter birthday: ");
  44. string birthday = Console.ReadLine();
  45. Console.Write("Enter gender: ");
  46. string gender = Console.ReadLine();
  47. AddUser(firstname, lastname, username, password, password2, email, location, birthday, gender);
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement