Beispiel #1
0
        public string Insert(InsertUser user)
        {
            string msg;

            con.Open();
            SqlCommand cmd = new SqlCommand("Insert into UserTab (Name, Email) values (@Name, @Email)", con);

            cmd.Parameters.AddWithValue("@Name", user.Name);
            cmd.Parameters.AddWithValue("@Email", user.Email);

            int g = cmd.ExecuteNonQuery();

            if (g == 1)
            {
                msg = "Successfully Inserted";
            }
            else
            {
                msg = "Failed to Insert";
            }
            return(msg);
        }
        public string Insert(InsertUser user)
        {
            string        msg;
            SqlConnection con = new SqlConnection("Data Source=WINDOWS-C8ATAQL;Initial Catalog=CRUD;Persist Security Info=True;User ID=sa; Password=pacitan1");

            con.Open();
            SqlCommand cmd = new SqlCommand("Insert into UserTab (Name, Email) values(@Name, @Email)", con);

            cmd.Parameters.AddWithValue("@Name", user.Name);
            cmd.Parameters.AddWithValue("@Email", user.Email);

            int g = cmd.ExecuteNonQuery();

            if (g == 1)
            {
                msg = "Successfuly Inserted";
            }
            else
            {
                msg = "Failed to Insert";
            }
            return(msg);
        }