Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is the code...
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 operationth : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection("server=SQLEXPRESS;user id=windows1;password=sqlserver;database=hospital");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
        }
    }
    
    
    protected void pttypeddl_SelectedIndexChanged(object sender, EventArgs e)
    {

        cn.Open();
        if (pttypeddl.SelectedItem.Value == "In-Patient")
        {
            SqlCommand cmd = new SqlCommand("select patientid from hospital_inpatient", cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            pidddl.DataSource = ds;
            pidddl.DataTextField = "patientid";
            pidddl.DataBind();
            pidddl.Items.Insert(0, "...Select...");
        }
        else
            if (pttypeddl.SelectedItem.Value == "Out-Patient")
        {
            SqlCommand cmd = new SqlCommand("select patientid from hospital_outpatient", cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            pidddl.DataSource = ds;
            pidddl.DataTextField = "patientid";
            pidddl.DataBind();
            pidddl.Items.Insert(0, "...Select...");
        }
       
        cn.Close();
    }
    protected void pidddl_SelectedIndexChanged(object sender, EventArgs e)
    {
       
       
        if (pttypeddl.SelectedItem.Value == "In-Patient")
        {
            cn.Open();
            SqlCommand cmd = new SqlCommand("select patientname,doctor from hospital_inpatient where patientid='"+ pidddl.Text +"'", cn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                pntxt.Text = dr[0].ToString();
                doctxt.Text = dr[1].ToString();
            }

            cn.Close();
        }
        else if (pttypeddl.SelectedItem.Value == "Out-Patient")
        {
            cn.Open();
            SqlCommand cmd = new SqlCommand("select patientname,assigndoctor from hospital_outpatient where patientid='"+ pidddl.Text +"'", cn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                pntxt.Text = dr[0].ToString();
                doctxt.Text = dr[1].ToString();
            }
             cn.Close();
        }
       
    }
   
    protected void sbtn_Click(object sender, EventArgs e)
    {
        cn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_hospital_operation";
        cmd.Connection = cn;

        SqlParameter p = new SqlParameter("@patienttype", SqlDbType.VarChar, 20);
        p.Value = pttypeddl.Text;
        cmd.Parameters.Add(p);

        SqlParameter p1 = new SqlParameter("@patientid", SqlDbType.Int);
        p1.Value = pidddl.Text;
        cmd.Parameters.Add(p1);

        SqlParameter p2 = new SqlParameter("@patientname", SqlDbType.VarChar, 20);
        p2.Value = pntxt.Text;
        cmd.Parameters.Add(p2);

        SqlParameter p3 = new SqlParameter("@refdoctor", SqlDbType.VarChar, 20);
        p3.Value = doctxt.Text;
        cmd.Parameters.Add(p3);

        SqlParameter p4 = new SqlParameter("@operationtype", SqlDbType.VarChar, 20);
        p4.Value = optddl.Text;
        cmd.Parameters.Add(p4);

        SqlParameter p5 = new SqlParameter("@operatonresult", SqlDbType.VarChar, 20);
        p5.Value = orddl.Text;
        cmd.Parameters.Add(p5);

        cmd.ExecuteNonQuery();
        cn.Close();
        Response.Redirect("laborataries.aspx");
        
    }
}


this is the asp



ASP.NET
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="operationth.aspx.cs" Inherits="operationth" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Image ID="Image1" runat="server" style="z-index: 100; left: 562px; position: absolute; top: 259px" Height="254px" ImageUrl="~/pics/operation1.jpg" Width="349px" />
    <asp:Label ID="Label1" runat="server" Text="Operation Theater..." style="z-index: 102; left: 130px; position: absolute; top: 179px" Font-Names="Modern" Font-Size="24pt" ForeColor="Red">
    <table style="z-index: 102; removed 124px; color: white; font-family: 'Lucida Console'; removed: absolute; removed 289px" id="TABLE1">
   <tr>
       <td>
            Patient Type
       </td>
       <td>
          &lt;asp:DropDownList ID="pttypeddl" runat="server" AutoPostBack="True" Width="157px" OnSelectedIndexChanged="pttypeddl_SelectedIndexChanged"&gt;
              &lt;asp:ListItem&gt;...Select...
              &lt;asp:ListItem&gt;In-Patient
              &lt;asp:ListItem&gt;Out-Patient
          
       </td>
   </tr>
   <tr>
       <td>
            Patient Id
       </td>
       <td>
           &lt;asp:DropDownList ID="pidddl" runat="server" AutoPostBack="True" Width="157px" OnSelectedIndexChanged="pidddl_SelectedIndexChanged"&gt;
             
       </td>
   </tr>
   <tr>
         <td>
             Patient Name
         </td>
         <td>
             &lt;asp:TextBox ID="pntxt" runat="server"&gt;
         </td>
   </tr>
   <tr>
         <td>
             Refered Doctor
         </td>
         <td>
             &lt;asp:TextBox ID="doctxt" runat="server"&gt;
         </td>
   </tr>
   <tr>
         <td>
              Operation Type
         </td>
         <td>
             &lt;asp:DropDownList ID="optddl" runat="server" Width="156px" &gt;
                 &lt;asp:ListItem&gt;...Select...
                 &lt;asp:ListItem&gt;Heart
                 &lt;asp:ListItem&gt;Brain
                 &lt;asp:ListItem&gt;Lungs
                 &lt;asp:ListItem&gt;Bone
          
         </td>
   </tr>
   <tr>
       <td>
            Operation Result
       </td>
       <td>
          &lt;asp:DropDownList ID="orddl" runat="server" Width="157px" OnSelectedIndexChanged="pttypeddl_SelectedIndexChanged"&gt;
              &lt;asp:ListItem&gt;...Select...
              &lt;asp:ListItem&gt;Success
              &lt;asp:ListItem&gt;Fail
          
       </td>
   </tr>
    
</table>
<table style="z-index: 103; removed 204px; removed: absolute; removed 475px">
<tr><td>
    &lt;asp:Button ID="sbtn" runat="server" Text="Submit" OnClick="sbtn_Click" /&gt;</td>
    <td>&lt;asp:Button ID="canbtn" runat="server" Text="Cancel" /&gt;</td>
</tr>
</table>


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 6-Feb-14 0:23am
v2
Comments
Pete O'Hanlon 6-Feb-14 6:24am    
This is just a code dump. It doesn't tell us what is wrong with the code. Is it causing an exception? If so, where? Is the page doing something you don't expect?

I appreciate that the issue is obvious to you, but we don't have access to your machine or your requirements so we cannot see what's going on.
OriginalGriff 6-Feb-14 6:25am    
I've tidied the question, so we can read it, but...

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
"this problem about thing related on the connect between the database and the code" doesn;t tell us much about what is wrong!
Use the "Improve question" widget to edit your question and provide better information.
Member 10576036 6-Feb-14 7:14am    
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)



thanks my friends for your attention about my problem ...but when i execute this program this message above appear to me .and i don't know how to solve it...
Member 10576036 6-Feb-14 7:23am    
and to be more specifically this message appear to me in the row 28...(cn.open())...here they show me the exception

1 solution

Your connection string is wrong. If you are truly using SQLExpress you need to use the appropriate connection string. The current string you are using is actually looking for a server on your network named SQLEXPRESS which from the error message it cannot connect too.
 
Share this answer
 

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