ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

ASP.NET and C# webform. Need help with query to DB

(1/2) > >>

I need a way to check my database and see if a record is repeated and if it's repeated twice.

I'm making a webform that will allow the user to enter his or her personal information and select a radio button of specific times.  The radio button will correspond to a SlotID in my database. When the SlotID has been used twice I need to grey out the radio button because it can no longer be selected. Any help would be nice.

I'm not sure what database you're using, but with ASP.NET and C#, I'll assume SQL Server.  Also assuming that the table name is Slot, and with everything else you've given, this query would give the number of times each SlotID has been used.

--- Code: Text ---SELECT count(1), SlotIDFROM SlotGROUP BY SlotID
If you only wanted to get the ones that had been used more than 1 time then you could add a having clause, i.e.

--- Code: Text ---SELECT count(1), SlotIDFROM SlotGROUP BY SlotIDHAVING count(1) > 1

What is count(1)?
I am using SQL server and my table is as follows:

Table AppointmentName: AppID, LastName, FirstName, Email, BirthDate, Slot.

Slot gets an SelectedIndexValue from the radio button on submitClick.

On Page_Load is where I need to have the SQL statement to see how many times the value from the column "Slot" has been used.

Count(1) just counts the number of records in the query.  You could use count(slotid), but by using 1, the data for the slotid doesn't have to actually be loaded.

I figured it out, thanks for the help.

--- Code: Text ---SELECT Slot, COUNT(Slot)AS SlotCountFROM AppointmentNameGROUP BY Slot


[0] Message Index

[#] Next page

Go to full version