Welcome Guest.   Make a donation to an author on the site August 01, 2014, 11:00:44 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Free DonationCoder.com Member Kit: Submit Request.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: ASP.NET and C# webform. Need help with query to DB  (Read 2573 times)
h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« on: July 30, 2009, 03:17:53 AM »

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.
Logged
wraith808
Supporting Member
**
Posts: 6,113



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: July 30, 2009, 09:16:02 AM »

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.

Formatted for SQL with the GeSHI Syntax Highlighter [copy or print]
  1. SELECT count(1), SlotID
  2. FROM Slot
  3. GROUP 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.

Formatted for SQL with the GeSHI Syntax Highlighter [copy or print]
  1. SELECT count(1), SlotID
  2. FROM Slot
  3. GROUP BY SlotID
  4. HAVING count(1) > 1

HTH
Logged

h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« Reply #2 on: July 30, 2009, 06:25:47 PM »

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.
« Last Edit: July 30, 2009, 07:49:23 PM by h0meopathic » Logged
wraith808
Supporting Member
**
Posts: 6,113



"In my dreams, I always do it right."

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: July 30, 2009, 09:21:03 PM »

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.
Logged

h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« Reply #4 on: July 30, 2009, 11:23:34 PM »

I figured it out, thanks for the help.

Formatted for SQL with the GeSHI Syntax Highlighter [copy or print]
  1. SELECT Slot, COUNT(Slot)
  2. AS SlotCount
  3. FROM AppointmentName
  4. GROUP BY Slot
Logged
h0meopathic
Participant
*
Posts: 24

View Profile Give some DonationCredits to this forum member
« Reply #5 on: July 31, 2009, 06:52:13 AM »

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. SqlConnection conn;
  2.        DataSet dataSet = new DataSet();
  3.        SqlDataAdapter adapter;
  4.        SqlCommandBuilder commandBuilder;
  5.  
  6.        conn = new SqlConnection("Server=localhost\\SqlExpress; Database=HealthFair;" +
  7.                "Integrated Security = True");
  8.        adapter = new SqlDataAdapter("SELECT Slot, COUNT(Slot) AS SlotCount FROM AppointmentName " +
  9.            "GROUP BY Slot HAVING COUNT(Slot) > 1", conn);
  10.        adapter.Fill(dataSet);
  11.        commandBuilder = new SqlCommandBuilder(adapter);
  12.        adapter.Update(dataSet);

Now how do I get the data into objects so I can determin which records in Slots to cut off?
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.045s | Server load: 0.2 ]