I am going to create a website for a hospital where I will store the following data;

  • Patients Data
  • Physicians Data
  • Medicine Data

If I am going perfect then first of all I will have to create a database in SQL Server.
Then Tables (Patient, Physicians and medicine)

A page in ASP.Net

When user will open the site, he'll have to enter the user name and password.
Then He will have the following pages
Patient Record.
Physicians Record.
Medicine Record.

I would like to get help about how to connect ASP.Net button connections to the database.


I would like to get help about how to connect ASP.Net button connections to the database.

Your question is too vague at this point. I dont see how we can help you with this based on what you have described so far.

In general, in your code behind page, you would create a click event and in that section of code, create the connection to your DB and execute your query and do something with the results.

How this code is written depends on the DB that you are using so you can create a connection string, or reference your connection string in the web.config file. Also, the syntax depends on if you are writing this in c# or vb.net.

What are you going to do with the results?

I agree with JorgeM here. Please be more specific. In your editor you should also have access to help files and exemples.

Try write the code and come back with what you have tried and specific questions.

I'm looking forward to seeing the results.

Thanks JorgeM and michel.cote.
Actually I am starting my work on the project tonight. First I will create a database with the name of Hospital_Db then I will create 4 tables,
1. Patient_T
2. Doctor_T
3. Medicine_T
4. User_T

Then I will create a page in ASP.Net. Where a user will be required to enter a user name and password. Then he/she'll get access to enter, delete, search or edit patient, doctor, medicine and user records.

Actually the main problem is that I am new to ASP.Net but have good command in SQL
Server. When I will complete the tables and start work in ASP.Net, then I'll come back and I'll paste the code time to time here.

Thanks for your time and support.


If this is for an assignment, or proof of concept, you could use visual studio and create a sample web application. It will set up a basic web app including login controls. You would just need to add connectivity to a database.

If you are new to ASP.NET, this may be too much since its going to generate a lot of file in the project and it may confuse you.

You could start a blank project and a sample project and use the code in the sample project to help guide you building this custom application.

Actually my uncle has a hospital. so he wants to computarize the record. Yes it could be considered as an assignment. BUt the limmitation is that I have to work according to his demands. I am also watching videos on youtube and have a bit idea clear. But actual game will begin when i will start work in ASP.Net and then will connect ASP.Net with SQL Server 2008 R2.

I think I will disturb you time to time as I'll be in ASP.Net. :)

Thanks and Regards.

@akkbkht your project is not small as it is.. it huge project. we've been creating that on my last company.. but since your just starting on that project you can start by the table creation.of course u must have patient table..patient table must generated patient number.. maybe arounf 10 char.. and must be increemented for every patient.. after that.. try to create for the maintenance table. i mean(his/her healthcard..insurance.)how bout the laboratory of the patient? billing? doctors schedule? room assignment? and others...

@cyberdaemon. Thanks for your reply.
The client has a small clinic type hospital. He just need to record the patient's history.
Only the following tables will be crated;

  1. Patient's Table,
  2. Doctor's Table,
  3. Medicine Table (Just 30 medicine),
  4. Check Table( That table will be used to record the number of patient's checkup. And will have weak relationship with patient's table).

I hope now you'll understand that this is large project but not too much large.
No Insurance, No Helath card. And for laboratory purpose, Just a table will be added in check Table.

This project is very good for me. I will learn too much and will have a good control on DBMS and ASP.Net as a professional programmer.


Another tip, you will wish to avoid SQL Injection Attacks where a user enters a damaging piece of SQL into an input that is then run on your SQL database as the input is processed by SQL Server.

  • Try to use and run stored procedures with parameters on the database rather than building queries on the fly
  • If you have to build a query on the fly, then use parameters
  • Connect to the database via a single SQL user that only has permission to execute the stored procedures you will be running.
  • Try and stop the damage in the first place by limiting input into textboxes etc i.e. maximum lengths, filtering input.

Thanks @G Waddell.
I am going to study the links you provided above. this will dafinately help me. please tell me something about relationships (one to one and one to many). and also diffirence between primary key and foriegn key.

Thanks and regards.

try to use software architecture for faster building of your apps.. and it's more secure.


commented: For what purpose software architecture is used? +1


You'll want to look at relation databases and design - quite a subject in it own right but in a nut shell: Suppose you have a table of doctors, a table patients and a table of visits.

Your doctor table contains all the data on your doctors but what if for example, you have two doctors named "John Smith" so you put a column in the doctor table that will uniquely identify each doctors record lets call it doctorID (as your using SQL Server make it an integer and enable Identity on the field,) now for each new doctor record entered the table will automatically populate the doctorID field with the next number in sequence. You can now mark this field as a PRIMARY KEY as it will be unique to each doctor i.e. there will be only one record with a DoctorID of 1.

Now for your patients you would do the same thing, except we'll call it PatientNumber. So You have two tables Patient and Doctor both with Primary Keys.

Now Patients Visit doctors and doctors take visits so your Visit table will link each patient and doctor to the history of the visit. First of all give Visit a primary Key just like you did to the others (VisitNumber?) Then you want to link the visit to the doctor - so you need a field in the visit table that links to the correct Doctor.... Now what do we have in the Doctors table that is unique to each doctor - you guessed it, the primary Key, DoctorID! So in your Visits table make a integer field called DoctorID this field will uniquely link each visit to the doctor and will link the doctor to each of his visits - This key is not created in the Visits table but the doctors table so it is a FOREIGN KEY used to link the tables. Now you do the same for Patient with the PatientNumber. So now Visit has two Foreign Keys DoctorID and PatientNumber and one Primary Key VisitNumber.

You will now be able to pull back all the visits a patient had:


Or all the visits a Doctor took:


Also a doctor can have many visits with many patients and a patient can have many visits with different doctors.

Hello everyone.
My programe is a bit changed. I am now doing all work in php with my sql using xampp. It simplify my work too much.

And @G Waddell, You are right. I will dafinately use Doctor ID. Uniqness is the key feature of any database and pre requirment. Thanks for your help.

Guide me that if i put 2 fileds on my index.php page and take 2 variables $u=username and $p=password. now i would like to code the login button something like that when a user enters a user name and password in the fields, the code should match the fields characters with the characters stored in variable $u and $p. if it is matched then go to main.php page else echo "the username and/or password incorrect."

What will be the syntax behind login button.

and how i will secure the safety of main.php page.
means if somone type in address bar localhost/main.php. so this page will open.

how i can secure the safety against unauthorised use? mean if somone want to directly accessthe main.php page, it prompts him/her to index.php for username and password entry.