Hi stabes,
stabes
At the top of the page there is a textbox which displays a value of the number of records for those marked as "Student" The database however distinguishes between whether a student "IsApproved" or not. I would like the textbox above to show only those who fall into the "IsApproved" category, no others. Presently it displays a global total.
If you just want to display the count of the approved student, you could try to use the following code to query the database and set the result to the TextBox.
try { string connectionString = ConfigurationManager.ConnectionStrings["UpdateDetailsConnectionString"].ConnectionString; string com ="select Count(*) from aspnet_Membership where IsApproved = 'IsApproved'"; using (var myConnection = new SqlConnection(connectionString)) { myConnection.Open(); var myCommand = new SqlCommand(com, myConnection); //Get the count Int32 count = (Int32) myCommand.ExecuteScalar(); //Set the TextBox value myConnection.Close(); } } catch (Exception ex) { Logger.Log(ex, "Memeber deactivation"); }
For more details about ExecuteScalar Method, please see: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar(v=vs.110).aspx
If you want to display the approved student in GridView, you could add the where clause in your query statement. Like this:
SELECT dbo.UserProfiles.UserId, dbo.UserProfiles.Surname, dbo.UserProfiles.FirstName,
dbo.UserProfiles.Organisation, dbo.UserProfiles.Address1, dbo.UserProfiles.Address2,
dbo.UserProfiles.Postcode, dbo.UserProfiles.MemberType, dbo.UserProfiles.DateLastPaid,
dbo.UserProfiles.Comments, dbo.UserProfiles.DateLastReminder, dbo.aspnet_Users.UserName,
dbo.aspnet_Membership.IsApproved FROM dbo.UserProfiles
INNER JOIN dbo.aspnet_Users ON dbo.UserProfiles.UserId = dbo.aspnet_Users.UserId
INNER JOIN dbo.aspnet_Membership ON dbo.aspnet_Users.UserId = dbo.aspnet_Membership.UserId
WHERE dbo.UserProfiles.MemberType = 'Student' And dbo.aspnet_Membership.IsApproved = 'IsApproved'
ORDER BY dbo.UserProfiles.Surname"
Best regards,
Dillion