Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
my .aspx file (doctorsignup.aspx)

ASP.NET
<%@ Page Language= "C# " MasterPageFile= "~/MasterPage.master " AutoEventWireup= "true " CodeFile= "doctorsignup.aspx.cs " Inherits= "doctorsignup " Title= "Untitled Page " % >
<asp:Content ID= "Content1 " ContentPlaceHolderID= "ContentPlaceHolder1 " Runat= "Server " >
    <asp:Label ID= "Label1 " runat= "server " Text= " Register Here  "
       style= "z-index: 100; left: 256px; position: absolute; top: 202px; width: 303px; "
       Font-Names= "Modern " Font-Size= "32pt " ForeColor= "Red " > </asp:Label >
    <table style= "z-index: 101; left: 234px; position: absolute; top: 275px; color: #ffffff; font-family:  'Lucida Console '; " >
    <tr > <td style= "height: 26px " >Name </td > <td style= "height: 26px " > <asp:TextBox ID= "nametxt " runat= "server " > </asp:TextBox > </td > <td style= "height: 26px; width: 157px; " >
        <asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " ErrorMessage= "Enter Name "
           Style= "position: relative " ControlToValidate= "nametxt " >* </asp:RequiredFieldValidator > </td > </tr >
    <tr > <td >Login Id </td > <td > <asp:TextBox ID= "lidtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " >
        <asp:RequiredFieldValidator ID= "RequiredFieldValidator2 " runat= "server " ErrorMessage= "Enter Login Id "
           Style= "position: relative " ControlToValidate= "lidtxt " >* </asp:RequiredFieldValidator > </td > </tr >

    <tr > <td >Password </td > <td > <asp:TextBox ID= "pwdtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " >
        <asp:RequiredFieldValidator ID= "RequiredFieldValidator4 " runat= "server " ControlToValidate= "pwdtxt "
           ErrorMessage= "Enter Password " Style= "position: relative " >* </asp:RequiredFieldValidator > </td > </tr >
    <tr > <td >Confirm Password </td > <td > <asp:TextBox ID= "conpwdtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " >
        <asp:CompareValidator ID= "CompareValidator1 " runat= "server " ControlToCompare= "pwdtxt "
           ControlToValidate= "conpwdtxt " ErrorMessage= "Not Matching " Style= "position: relative " >* </asp:CompareValidator > </td > </tr >
    <tr > <td >Department </td > <td >
        <asp:DropDownList ID= "depddl " runat= "server " Width= "153px " >
            <asp:ListItem >----Select---- </asp:ListItem >
            <asp:ListItem >Cardiology </asp:ListItem >
            <asp:ListItem >Neurology </asp:ListItem >
            <asp:ListItem >Opthalmology, </asp:ListItem >
            <asp:ListItem >Nephrology </asp:ListItem >
            <asp:ListItem >Surgery </asp:ListItem >
            <asp:ListItem >Pediatrics </asp:ListItem >
        </asp:DropDownList > </td > <td style= "width: 157px " >
            <asp:RequiredFieldValidator ID= "RequiredFieldValidator3 " runat= "server " ControlToValidate= "depddl "
               ErrorMessage= "Enter Your Department " Style= "position: relative " >* </asp:RequiredFieldValidator > </td > </tr >
    <tr > <td >Specialization </td > <td >
        <asp:DropDownList ID= "speddl " runat= "server " Width= "154px " >
            <asp:ListItem >----Select---- </asp:ListItem >
            <asp:ListItem >Pulmonology </asp:ListItem >
            <asp:ListItem >Cardiology </asp:ListItem >
            <asp:ListItem >Neurology </asp:ListItem >
            <asp:ListItem >Nephrology </asp:ListItem >
            <asp:ListItem >Opthalmology </asp:ListItem >
        </asp:DropDownList > </td > <td style= "width: 157px " >
            <asp:RequiredFieldValidator ID= "RequiredFieldValidator5 " runat= "server " ControlToValidate= "speddl "
               ErrorMessage= "Specialization " Style= "position: relative " >* </asp:RequiredFieldValidator > </td > </tr >
    <tr > <td >Phone Number </td > <td > <asp:TextBox ID= "phtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " > </td > </tr >
    <tr > <td >Address </td > <td > <asp:TextBox ID= "addtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " > </td > </tr >
    <tr > <td >E-Mail </td > <td > <asp:TextBox ID= "emtxt " runat= "server " > </asp:TextBox > </td > <td style= "width: 157px " >
        <asp:RegularExpressionValidator ID= "RegularExpressionValidator1 " runat= "server " ControlToValidate= "emtxt "
           ErrorMessage= "Incorrect Format " Style= "position: relative " ValidationExpression= "\w+([-+. ']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* " >* </asp:RegularExpressionValidator > </td > </tr >
    </table >
    <table style= "z-index: 101; left: 299px; position: absolute; top: 549px; font-weight: bold; color: #ffffff; font-family:  'Lucida Console '; " >
    <tr > <td style= "width: 88px " >
        <asp:Button ID= "subbtn " runat= "server " Text= "Submit " Width= "94px " OnClick= "subbtn_Click " / > </td >
        <td style= "width: 93px " >
        <asp:Button ID= "Resbtn " runat= "server " Text= "Reset " Width= "94px " OnClick= "Resbtn_Click " / > </td >
     <td style= "width: 93px " >
        <asp:Button ID= "canbtn " runat= "server " Text= "Cancel " Width= "94px " OnClick= "canbtn_Click " / > </td > </tr >
    </table >
</asp:Content >



.aspx.cs file (doctorsignup.aspx.cs)
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class doctorsignup : System.Web.UI.Page
{
   // this is already written code should replace if the code wont work below) SqlConnection cn = new SqlConnection(@&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Angel\Desktop\Hospital Management System ASP.NET Project\Hospital Management System Source Code\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True&quot;);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected virtual void subbtn_Click(object sender, EventArgs e)
    {
        // this is for above database connection)//cn.Open();

        try
        {
            SqlConnection cn = new SqlConnection(@&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Angel\Desktop\Hospital Management System ASP.NET Project\Hospital Management System Source Code\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True&quot;);
            SqlCommand command = new SqlCommand(&quot;sp_hospital_doctorsignup&quot;, cn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(&quot;@name&quot;,SqlDbType.VarChar,20).Value = nametxt.Text;
            command.Parameters.Add(&quot;@loginid&quot;,SqlDbType.VarChar,20).Value = lidtxt.Text;
            command.Parameters.Add(&quot;@password&quot;,SqlDbType.VarChar,20).Value = pwdtxt.Text;
            command.Parameters.Add(&quot;@department&quot;,SqlDbType.VarChar,20).Value = depddl.Text;
            command.Parameters.Add(&quot;@specialization&quot;,SqlDbType.VarChar,20).Value = speddl.Text;
            command.Parameters.Add(&quot;@phonenumber&quot;, SqlDbType.BigInt).Value = phtxt.Text;
            command.Parameters.Add(&quot;@address&quot;,SqlDbType.VarChar,40).Value = addtxt.Text;
            command.Parameters.Add(&quot;@email&quot;,SqlDbType.VarChar,20).Value = emtxt.Text;            
            cn.Open();
            return command.ExecuteNonQuery();
            cn.Close();
        }
        catch (SqlException ex)
        {
            Console.WriteLine(&quot;SQL Error&quot; + ex.Message.ToString());
            return 0;
            
        }


// the below code is written by me to the stored procedure .its going o stored procedure but its not calling the procedure .so am modifying this block of code with the other code and for a rference am keeeping the below code from here to emtxt in comment lines
C#
        /*SqlCommand cmd =new SqlCommand(&quot;sp_hospital_doctorsignup&quot;, cn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(&quot;@name&quot;, nametxt);
        cmd.Parameters.Add(&quot;@loginid&quot;, lidtxt);
        cmd.Parameters.Add(&quot;@password&quot;, pwdtxt);
        cmd.Parameters.Add(&quot;@department&quot;, depddl);
        cmd.Parameters.Add(&quot;@specialization&quot;, speddl);
        cmd.Parameters.Add(&quot;@phonenumber&quot;, phtxt);
        cmd.Parameters.Add(&quot;@address&quot;, addtxt);
        cmd.Parameters.Add(&quot;@email&quot;, emtxt);   */         // this is my code 
       /* SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = &quot;sp_hospital_doctorsignup&quot;;
        cmd.Connection = cn;


        SqlParameter name  = new SqlParameter(&quot;@name&quot;, SqlDbType.VarChar, 20);
        name.Value = nametxt.Text;
        cmd.Parameters.Add(name);

        SqlParameter loginid = new SqlParameter(&quot;@loginid&quot;, SqlDbType.VarChar, 20);
        loginid.Value = lidtxt.Text;
        cmd.Parameters.Add(loginid);

        SqlParameter password = new SqlParameter(&quot;@password&quot;, SqlDbType.VarChar, 20);
        password.Value = pwdtxt.Text;
        cmd.Parameters.Add(password);

        SqlParameter department = new SqlParameter(&quot;@department&quot;, SqlDbType.VarChar, 20);
        department.Value = depddl.Text;
        cmd.Parameters.Add(department);

        SqlParameter specialization = new SqlParameter(&quot;@specialization&quot;, SqlDbType.VarChar, 20);
        specialization.Value = speddl.Text;
        cmd.Parameters.Add(specialization);

        SqlParameter phonenumber = new SqlParameter(&quot;@phonenumber&quot;, SqlDbType.BigInt);
        phonenumber.Value = phtxt.Text;
        cmd.Parameters.Add(phonenumber);

        SqlParameter address = new SqlParameter(&quot;@address&quot;, SqlDbType.VarChar, 40);
        address.Value = addtxt.Text;
        cmd.Parameters.Add(address);

        SqlParameter email = new SqlParameter(&quot;@email&quot;, SqlDbType.VarChar, 20);
        email.Value = emtxt.Text;
        cmd.Parameters.Add(email);*/

        //cmd.ExecuteNonQuery();
        
       //this my previous code line// cn.Close();
        Response.Redirect(&quot;doctorlogin.aspx&quot;);

    }
    protected void Resbtn_Click(object sender, EventArgs e)
    {
        Response.Redirect(&quot;doctorsignup.aspx&quot;);
    }
    protected void canbtn_Click(object sender, EventArgs e)
    {
        Response.Redirect(&quot;doctorlogin.aspx&quot;);
    }
}


the stored procedure i used here is
sp_hospital_doctorsignup
SQL
ALTER PROCEDURE dbo.sp_hospital_doctorsignup
(
@name varchar(20),
@loginid varchar(20),
@password varchar(20),
@department varchar(20),
@specialization varchar(20),
@phonenumber bigint,
@address varchar(40),
@email varchar(20)
)
as
begin
SET NOCOUNT ON;
begin
insert into hospital_doctorsignup values(@name,@loginid,@password,@department,@specialization,@phonenumber,@address,@email)
end
end



the table i created

hospital_doctorsignup

Table For Doctor Register
SQL
create table hospital_doctorsignup
(
 name varchar(20), 
 loginid varchar(20),
 password varchar(20),
 department varchar(20),
 specialization varchar(20),
 phonenumber bigint,
 address varchar(20),
 email varchar(20)
)



friends i had tried lot of blocks f code from code project itself but no one specified the entire code and am a beginner and am quite confused with this code .as u may see in comment lines i had written that its my code .by using that code am able to call the procedure but am not able to store the procedure .when i insert the values in registration form its redirecting me to the doctors login page but its not storing any values in the respective connected table which i had mentioned in the sp_hospital_doctorsignup stored procedure .i want to read the user inputs into the stored procedure .please help me to complete my project .if u wan me to mail my project to u am happy to do that but i want solution before 1st june 2016.please help me friends jus set a page for me .i will try to set other pages.
if u r setting the page plz mention the use of code in the comment line in each line of code.its a request.thanks in advance .thank you

What I have tried:

friends i had tried almost everything but am unable to place the block of code at right place.if u can plz set this page so i can execute the stored procedure and the values into my table hospital_doctorsignup.
Posted
Updated 29-May-16 1:04am
v3
Comments
George Jonsson 29-May-16 5:59am    
I tried to format the code, but the first part is a mess. You have to paste it again, I think.
Patrice T 29-May-16 6:21am    
reformatted first part
George Jonsson 29-May-16 6:29am    
Why do you post your code here in the comment section?
George Jonsson 29-May-16 6:38am    
Use Improve question and either add new code or replace existing.
Sheerin Shaik 29-May-16 6:43am    
can u fix the problem?

1 solution

Not sure which code block you want to keep, so I used the uncommented code.

1. You should always use the using statement, as it will close the connection automatically or use try-catch-finally
2. You forgot to assign the CommandText property
3. You have an integer type in your parameter list, but you assign a string.
It is good practice to use the proper type.

[UPDATE] Change to try-catch-finally instead of using
C#
SqlConnection cn = null;
try
{
    cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Angel\Desktop\Hospital Management System ASP.NET Project\Hospital Management System Source Code\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True")

    SqlCommand command = new SqlCommand("sp_hospital_doctorsignup", cn);
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "sp_hospital_doctorsignup";
    command.Parameters.Add("@name",SqlDbType.VarChar,20).Value = nametxt.Text;
    command.Parameters.Add("@loginid",SqlDbType.VarChar,20).Value = lidtxt.Text;
    command.Parameters.Add("@password",SqlDbType.VarChar,20).Value = pwdtxt.Text;
    command.Parameters.Add("@department",SqlDbType.VarChar,20).Value = depddl.Text;
    command.Parameters.Add("@specialization",SqlDbType.VarChar,20).Value = speddl.Text;
    command.Parameters.Add("@phonenumber", SqlDbType.BigInt).Value = long.Parse(phtxt.Text);
    command.Parameters.Add("@address",SqlDbType.VarChar,40).Value = addtxt.Text;
    command.Parameters.Add("@email",SqlDbType.VarChar,20).Value = emtxt.Text;
    
    cn.Open();
    command.ExecuteNonQuery(); // Nothing to return. Right?

    // this code would never be called in your original code and with the using statement
    // it is not necessary
    // cn.Close(); 
}
catch (Exception ex)
{
    // Do error handling
}
finally
{
    if (cn != null)
        cn.Close();
}


End note
If you have a dead line, it is your concern. Don't add that in your question.
Also try to use proper writing, like using punctuation and start a sentence with a capital letter.
 
Share this answer
 
v3
Comments
Sheerin Shaik 29-May-16 7:12am    
could you plz make it little bit clear by mailing me the entire page on happylearning786@gmail.com ? it will be very helpful
George Jonsson 29-May-16 7:14am    
You have a subbtn_Click method. I thought you wanted the code there.
Sheerin Shaik 29-May-16 7:29am    
doctorsignup.command is a field but it is used like a type
Sheerin Shaik 29-May-16 7:15am    
its not working i kept at first place
George Jonsson 29-May-16 7:22am    
What is not working? Isn't the method called when you click the button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900