Delete User from SqlConnection - CSharp System.Data.SqlClient

CSharp examples for System.Data.SqlClient:SqlConnection

Description

Delete User from SqlConnection

Demo Code


using System.Web;
using System.Linq;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Generic;
using System;//from   w ww .  j  a  v a2 s .c om

public class Main{
        public static void DeleteUser(string UserId)
        {
            try
            {
                SqlConnection sqlConnection1 = new SqlConnection("Server=tcp:plps.database.windows.net,1433;Initial Catalog=PLPS;Persist Security Info=False;User ID=tomasoft;Password=Tomason18,;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                SqlCommand cmd = new SqlCommand();
                SqlDataReader reader;

                cmd.CommandText = "Delete [dbo].[UserPolsatSport] where UserId='" + UserId + "'";
                cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlConnection1;

                sqlConnection1.Open();
                cmd.ExecuteNonQuery();

                sqlConnection1.Close();
            }
            catch
            {
                AddToLog("Blad usuwania uzytkownika: " + UserId);
            }
        }
}

Related Tutorials