daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         //insert a new user to the database
  2.         public void writeUserToDatabase(string groupid, string username, string password)
  3.         {//"SET IDENTITY_INSERT dbo.Users ON" +
  4.             sql_query = $" INSERT INTO [dbo].[Users] (Group_Id,Nickname,Password)"
  5.                 +" VALUES (@groupid,@username,@password)";
  6.             command = new SqlCommand(sql_query, connection);
  7.  
  8.             try
  9.             {
  10.                 connection.Open();
  11.                 int gid = int.Parse(groupid);
  12.                 SqlParameter groupid_param = new SqlParameter("@groupid", SqlDbType.Int, 4);
  13.                 SqlParameter username_param = new SqlParameter("@username", SqlDbType.Char, 8);
  14.                 SqlParameter password_param = new SqlParameter("@password", SqlDbType.Char, 64);
  15.                
  16.  
  17.                 groupid_param.Value = gid;
  18.                 username_param.Value = username;
  19.                 password_param.Value = password;
  20.                
  21.                 command.Parameters.Add(groupid_param);
  22.                 command.Parameters.Add(username_param);
  23.                 command.Parameters.Add(password_param);
  24.                  
  25.                 command.ExecuteNonQuery();
  26.                 command.Dispose();
  27.                 connection.Close();
  28.             }
  29.             catch (Exception e)
  30.             {
  31.                 command.Dispose();
  32.                 connection.Close();
  33.                 Logger.Instance.AddLogMessage("Error : DatabaseManager : Could not write user to database.");
  34.                 throw new Exception("Could not write user to database.");
  35.             }
  36.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top