After I learned how to hide database records based on condition, I was wondering if this is how I can also do same in C#, to show records that are not affiliated with a particular email. For example, an email (richard@gmail.com) exists in column (CreatedBy), and I don’t want to show records that are associated with (richard@gmail.com).
This is how I was taught in stored procedure
ALTER PROCEDURE [dbo].[UserData]
@CreatedBy VARCHAR(50)
,@PageIndex INT
,@PageSize INT
,@RecordCount INT OUT
AS
BEGIN
SELECT ROW_NUMBER() OVER(ORDER BY email) RowNumber
,Name
,email
,name
,CreatedBy
INTO #Temp
FROM Users
WHERE email NOT IN('richard@gmail.com') OR CreatedBy NOT IN('richard@gmail.com')
SELECT @RecordCount = COUNT(*) FROM #Temp
SELECT * FROM #Temp
WHERE (RowNumber BETWEEN ((@PageIndex-1) * @PageSize) + 1 AND (@PageIndex * @PageSize)) OR @PageIndex = - 1
DROP TABLE #Temp
END
I also want to know if it can be done in C#, so I tried this but it did not work
private void CountTeam()
{
string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Users WHERE email NOT IN('quirver@quirver.com') OR CreatedBy NOT IN('quirver@quirver.com')", con);
//cmd.Parameters.AddWithValue("@CreatedBy", createby.Text.Trim());
int count = Convert.ToInt32(cmd.ExecuteScalar());
team.Text = count.ToString();
con.Close();
}
}