Hi my name is vishal.
For the past 1 week i been in the process of creating a dashboard using listview in c# windows forms with sql server 2008.
I created listview named lstDashItems and populate it from a table named USERACTIVITIES in sql server 2008.
The design of USERACTIVITIES table in sql server 2008.

 Column Name     Data Type      Allow Nulls
    user_id         int              yes
    row_upd_date    datetime         yes
    activity        varchar(50)      yes
    type            int              yes
    ref_id          numeric(18,0)    yes


I have created a method in MdiParent Form named updateUserActivities()
Given below is the code in my MdiParent Form of Method/function updateUserActivities:



  public void updateUserActivities(long refID, int ActType, string ActivityStr)
        {

            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            SqlCommand cmd = new SqlCommand("Insert into USERACTIVITIES(user_id,row_upd_date,activity,type,ref_id)" + "Values(@user_id,GetDate(),@activity,@type,@ref_id)", conn);
            conn.Open();
            {
                cmd.Parameters.AddWithValue("@user_id", pUserID);
                cmd.Parameters.AddWithValue("@activity", ActivityStr);
                cmd.Parameters.AddWithValue("@type", ActType);
                cmd.Parameters.AddWithValue("@ref_id", refID);
                cmd.ExecuteNonQuery();
            }
            conn.Close();
        }

Given below is code of form named Patient:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class Patient : Form
    {
        long pUserID = 1;
        long patientID;
        string mpatientID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Patient()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(conString);

            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString, conn);
            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            string SqlDataPull = ("Select doctor_first_name,doctor_last_name,doctor_middle_name from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id");
            SqlCommand cmd = new SqlCommand(SqlDataPull);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                SqlDataPull = dr[0].ToString()+dr[1].ToString()+dr[2].ToString();

                cboDoctor.Items.Add(SqlDataPull);
            }
            dr.Close();
        }


        private void Patient_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;
        }

        public void loadPatient(string mpatientID)
        {
            button1.Text = "Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString,conn);


            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            dataset = new DataSet();
            adp.Fill(dataset, "PATIENT_ID6");
            adp.Fill(dataset, "PATIENT_NAME6");
            adp.Fill(dataset, "ADDRESS7");
            adp.Fill(dataset, "PATIENT_CONTACT6");
            adp.Fill(dataset, "DOCTORDETAIL");

                dtDOB.DataBindings.Add("Text",dataset,"PATIENT_ID6.patient_dob");
                txtFname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_fname");
                txtMname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_mname");
                txtLname.DataBindings.Add("Text", dataset, "PATIENT_NAME6.patient_lname");
                cboSex.DataBindings.Add("Text", dataset, "PATIENT_ID6.patient_sex");
                cboVirology.DataBindings.Add("Text", dataset, "PATIENT_NAME6.virology");
                txtApartmentName.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_name");
                txtDoorNo.DataBindings.Add("Text", dataset, "ADDRESS7.door_number");
                txtStreet1.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_1");
                txtStreet2.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_2");
                txtStreet3.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_3");
                txtVillageArea.DataBindings.Add("Text", dataset, "ADDRESS7.village");
                txtCity.DataBindings.Add("Text", dataset, "ADDRESS7.city");
                txtState.DataBindings.Add("Text", dataset, "ADDRESS7.State");
                txtCountry.DataBindings.Add("Text", dataset, "ADDRESS7.country");
                txtApartmentNo.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_number");
                txtPostalCode.DataBindings.Add("Text", dataset, "ADDRESS7.pincode");
                txtHnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.homenumber");
                txtMnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.mobilenumber");
                cboDoctor.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_name");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            long patientID = 0;
            string dFieldName = "";
            Boolean vEmptyB=false;
            int vPatientID = 0;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "First Name should not be empty";

            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Sex should not be empty";
            }
            else if (cboVirology.SelectedIndex == -1)
            {
                vEmptyB=true;
                dFieldName = "Virology state of patient should not be empty";
            }
            else if (txtHnumber.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Home number of patient should not be empty";
            }
            if ((txtHnumber.Text.Length < 10) && (txtHnumber.Text.Length > 0))
            {
                vEmptyB = true;
                dFieldName = "Entered phone number was must have digits of ten numbersus which includes extension code also";
                txtHnumber.Focus();
            }

            else if (txtCity.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "City of patient should not be empty";
            }
            else if (txtCountry.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Country of patient should not be empty";
            }
            else if (cboDoctor.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Doctor Name should not be empty";
            }
            if (vEmptyB==true)
            {
                MessageBox.Show(dFieldName+"should not be empty");
                return;
            }


            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd = new SqlCommand("Insert into PATIENT_ID6(patient_sex,patient_dob,row_upd_date,user_id)" + "Values(@patient_sex,@patient_dob,GetDate(),@user_id)", conn);
            if (patientID == 0)
            {
                if (cboSex.SelectedIndex == 0)
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "M";
                }
                else
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "F";
                }

                cmd.Parameters.AddWithValue("@patient_dob", dtDOB.Value.ToString("dd-MMM-yyyy"));
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }
            if (patientID > 0)
            {
                cmd = new SqlCommand("update PATIENT_NAME6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into PATIENT_NAME6(patient_first_name,patient_middle_name,patient_last_name,virology,row_upd_date,status,user_id)" + "Values(@patient_first_name,@patient_middle_name,@patient_last_name,@virology,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@patient_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@patient_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@patient_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@virology", cboVirology.SelectedIndex);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if ((txtHnumber.Text != "") || (txtMnumber.Text != ""))
            {
                if (patientID > 0)
                {
                    cmd = new SqlCommand("Update PATIENT_CONTACT6 set status=false where patient_id=" + patientID);
                }
                cmd = new SqlCommand("Insert into PATIENT_CONTACT6(homenumber,mobilenumber,status,row_upd_date,user_id)" + "Values(@homenumber,@mobilenumber,@status,GetDate(),@user_id)", conn);
                cmd.Parameters.AddWithValue("@homenumber", txtHnumber.Text);
                cmd.Parameters.AddWithValue("@mobilenumber", txtMnumber.Text);
                cmd.Parameters.AddWithValue("@status", true);
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }

            if (patientID > 0)
            {
                cmd = new SqlCommand("Update ADDRESS7 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into ADDRESS7(apartment_name,door_number,street_name_1,street_name_2,street_name_3,village,city,state,country,row_upd_date,apartment_number,status,pincode,user_id)" + "Values(@apartment_name,@door_number,@street_name_1,@street_name_2,@street_name_3,@village,@city,@state,@country,GetDate(),@apartment_number,@status,@pincode,@user_id)", conn);
            cmd.Parameters.AddWithValue("@apartment_name", txtApartmentName.Text);
            cmd.Parameters.AddWithValue("@door_number", txtDoorNo.Text);
            cmd.Parameters.AddWithValue("@street_name_1", txtStreet1.Text);
            cmd.Parameters.AddWithValue("@street_name_2", txtStreet2.Text);
            cmd.Parameters.AddWithValue("@street_name_3", txtStreet3.Text);
            cmd.Parameters.AddWithValue("@village", txtVillageArea.Text);
            cmd.Parameters.AddWithValue("@city", txtCity.Text);
            cmd.Parameters.AddWithValue("@state", txtState.Text);
            cmd.Parameters.AddWithValue("@country", txtCountry.Text);
            cmd.Parameters.AddWithValue("@apartment_number", txtApartmentNo.Text);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@pincode", txtPostalCode.Text);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if (patientID > 0)
            {
                cmd = new SqlCommand("Update DOCTORPATIENT6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into DOCTORPATIENT6(doctor_id,row_upd_date,status,user_id)" + "Values(@doctor_id,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@doctor_id", cboDoctor.GetItemText(cboDoctor.SelectedIndex));
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();




            ((MDIParent5)this.MdiParent).updateUserActivities(vPatientID, 1, txtFname.Text + "Patient detail was added successfully");
            MessageBox.Show("Patient detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtHnumber_TextChanged(object sender, EventArgs e)
        {
            string s = txtHnumber.Text;
            Int32 result = 0;
            Int32.TryParse(s, out result);
            if (result == 0)
            {
                MessageBox.Show("Please enter phone number values", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


        }

        private void txtMnumber_TextChanged(object sender, EventArgs e)
        {
            string s =txtMnumber.Text;
            Int32 result = 0;
            Int32.TryParse(s, out result);
            if (result == 0)
            {
                MessageBox.Show("Please enter mobile number values", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }


    }
}

Given below is code of form named Doctor:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DRRS_in_Csharp
{
    public partial class Doctor : Form
    {
        long doctorID;
        long pUserID;
        string mDoctorID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Doctor()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(conString);
            conn.Open();
            string selectString = ("Select p.doctor_id as doctor_id,p.doctor_dob as doctor_dob,n.doctor_first_name as doctor_fname, n.doctor_middle_name as doctor_mname,n.doctor_last_name as doctor_lname,p.doctor_sex as doctor_sex from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id and p.doctor_id=@doctorId");
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
            dap.SelectCommand.Parameters.Add("@doctorId", SqlDbType.VarChar, 50);
            dap.SelectCommand.Parameters["@doctorId"].Value = mDoctorID;
        }

        public void loadDoctor(string mDoctorID)
        {
            button1.Text="Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.doctor_id as doctor_id,p.doctor_dob as doctor_dob,n.doctor_first_name as doctor_fname, n.doctor_middle_name as doctor_mname,n.doctor_last_name as doctor_lname,p.doctor_sex as doctor_sex from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id and p.doctor_id=@doctorId");
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
            dap.SelectCommand.Parameters.Add("@doctorId", SqlDbType.VarChar, 50);
            dap.SelectCommand.Parameters["@doctorId"].Value = mDoctorID;
            dataset = new DataSet();
            dap.Fill(dataset, "DOCTORDETAIL");
            dap.Fill(dataset, "DOCTOR3");
            txtFname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_fname");
            txtMname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_mname");
            txtLname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_lname");
            cboSex.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_sex");
            dtDOB.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_dob");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string dFieldName = "";
            Boolean vEmptyB = false;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "First name should not be empty";
            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Sex of doctor should not be empty";
            }
            if (vEmptyB==true)
            {
                MessageBox.Show(dFieldName + "should not be empty");
                return;
            }
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            if (doctorID == 0)
            {
                cmd = new SqlCommand("Insert into DOCTOR3(doctor_sex,doctor_dob,created_date,user_id)" + "Values(@doctor_sex,@doctor_dob,GetDate(),@user_id)", conn);
                if (cboSex.SelectedIndex == 0)
                {
                    cmd.Parameters.AddWithValue("@doctor_sex", SqlDbType.VarChar).Value = "M";
                }
                else
                {
                    cmd.Parameters.AddWithValue("@doctor_sex", SqlDbType.VarChar).Value = "F";
                }
                cmd.Parameters.AddWithValue("@doctor_dob", dtDOB.Value);
                cmd.Parameters.AddWithValue("@user_id", pUserID);
                cmd.ExecuteNonQuery();
            }
            if (doctorID == 0)
            {
                cmd = new SqlCommand("Update DOCTORDETAIL set status=false where doctor_id=" + doctorID);
            }
            cmd = new SqlCommand("Insert into DOCTORDETAIL(doctor_first_name,doctor_middle_name,doctor_last_name,status,row_upd_date,user_id)" + "Values(@doctor_first_name,@doctor_middle_name,@doctor_last_name,@status,GetDate(),@user_id)", conn);
            cmd.Parameters.AddWithValue("@doctor_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@doctor_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@doctor_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            ((MDIParent5)this.MdiParent).updateUserActivities(pUserID, 2, txtFname.Text + "doctor detail was added successfully");
            MessageBox.Show("Doctor Detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();

        }

        private void Doctor_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;  
    }

        private void cboSex_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selecteditem = cboSex.SelectedIndex;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

now in my dashboard form i have populated listview named lstDashItems using following code and it kinda works except it displays date and time on when data was entered in table to certain rows only and i dont know why?.
here is the code below on how i populate my listview named lstDashItems.:

 private void DashBoard_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            lstDashItems.Items.Clear();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            DataSet ds;
            SqlDataAdapter adp = new SqlDataAdapter();
            cmd = new SqlCommand("Select * from USERACTIVITIES where user_id=" + pUserID + "Order by row_upd_date desc", conn);
            adp = new SqlDataAdapter(cmd);
            ds = new DataSet();
            adp.Fill(ds, "USERACTIVITIES");
            dt = ds.Tables["USERACTIVITIES"];
            lstDashItems.Columns.Add("Task", 340, HorizontalAlignment.Left);
            lstDashItems.Columns.Add("Date", 492, HorizontalAlignment.Right);
            lstDashItems.View = View.Details;


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lstDashItems.Items.Add(dt.Rows[i].ItemArray[2].ToString());
                lstDashItems.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
            }




        }

now the tricky part is when my form(windows forms) named DashBoard.cs loads it contains all the datas that have been entered in each forms. So lots of rows appear.

i have enabled double click event of my listview in below following code

`

public DashBoard()
        {
            InitializeComponent();   
            this.lstDashItems.DoubleClick += new System.EventHandler(this.lstDashItems_DoubleClick);
        }

`

What i want is when user double clicks a row from listview(patient data or doctor data) it should go respective form with their data.

Now i know i could put if condition in terms of selecting form. The type field in USERACTIVITIES table contains values(1 for patient data,2 for doctor data).

Now i know i could type field value in if condition in terms of selecting respective forms. But i dont know how to do it or i am confused on how to use type field value from USERACTIVITIES table in if condition in DashBoard.cs windows forms.

Can anyone help me please? i am going nuts over this problem. Any help or guidance would be greatly appreciated.

i have tried the some code below:.
In Patient form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class Patient : Form
    {
        long pUserID = 1;
        long patientID;
        string mpatientID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Patient()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(conString);

            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString, conn);
            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            string SqlDataPull = ("Select doctor_first_name,doctor_last_name,doctor_middle_name from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id");
            SqlCommand cmd = new SqlCommand(SqlDataPull);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                SqlDataPull = dr[0].ToString()+dr[1].ToString()+dr[2].ToString();

                cboDoctor.Items.Add(SqlDataPull);
            }
            dr.Close();
        }


        private void Patient_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;
        }

        public void loadPatient(string mpatientID)
        {
            button1.Text = "Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString,conn);


            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            dataset = new DataSet();
            adp.Fill(dataset, "PATIENT_ID6");
            adp.Fill(dataset, "PATIENT_NAME6");
            adp.Fill(dataset, "ADDRESS7");
            adp.Fill(dataset, "PATIENT_CONTACT6");
            adp.Fill(dataset, "DOCTORDETAIL");

                dtDOB.DataBindings.Add("Text",dataset,"PATIENT_ID6.patient_dob");
                txtFname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_fname");
                txtMname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_mname");
                txtLname.DataBindings.Add("Text", dataset, "PATIENT_NAME6.patient_lname");
                cboSex.DataBindings.Add("Text", dataset, "PATIENT_ID6.patient_sex");
                cboVirology.DataBindings.Add("Text", dataset, "PATIENT_NAME6.virology");
                txtApartmentName.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_name");
                txtDoorNo.DataBindings.Add("Text", dataset, "ADDRESS7.door_number");
                txtStreet1.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_1");
                txtStreet2.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_2");
                txtStreet3.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_3");
                txtVillageArea.DataBindings.Add("Text", dataset, "ADDRESS7.village");
                txtCity.DataBindings.Add("Text", dataset, "ADDRESS7.city");
                txtState.DataBindings.Add("Text", dataset, "ADDRESS7.State");
                txtCountry.DataBindings.Add("Text", dataset, "ADDRESS7.country");
                txtApartmentNo.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_number");
                txtPostalCode.DataBindings.Add("Text", dataset, "ADDRESS7.pincode");
                txtHnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.homenumber");
                txtMnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.mobilenumber");
                cboDoctor.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_name");

        }

In Doctor form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DRRS_in_Csharp
{
    public partial class Doctor : Form
    {
        long doctorID;
        long pUserID;
        string mDoctorID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Doctor()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(conString);
            conn.Open();
            string selectString = ("Select p.doctor_id as doctor_id,p.doctor_dob as doctor_dob,n.doctor_first_name as doctor_fname, n.doctor_middle_name as doctor_mname,n.doctor_last_name as doctor_lname,p.doctor_sex as doctor_sex from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id and p.doctor_id=@doctorId");
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
            dap.SelectCommand.Parameters.Add("@doctorId", SqlDbType.VarChar, 50);
            dap.SelectCommand.Parameters["@doctorId"].Value = mDoctorID;
        }

        public void loadDoctor(string mDoctorID)
        {
            button1.Text="Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.doctor_id as doctor_id,p.doctor_dob as doctor_dob,n.doctor_first_name as doctor_fname, n.doctor_middle_name as doctor_mname,n.doctor_last_name as doctor_lname,p.doctor_sex as doctor_sex from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id and p.doctor_id=@doctorId");
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
            dap.SelectCommand.Parameters.Add("@doctorId", SqlDbType.VarChar, 50);
            dap.SelectCommand.Parameters["@doctorId"].Value = mDoctorID;
            dataset = new DataSet();
            dap.Fill(dataset, "DOCTORDETAIL");
            dap.Fill(dataset, "DOCTOR3");
            txtFname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_fname");
            txtMname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_mname");
            txtLname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_lname");
            cboSex.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_sex");
            dtDOB.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_dob");
        }

In DashBoard form in lstDashItems Double Click event:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class DashBoard : Form
    {
        long pUserID;
        private FormWindowState normal;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        public DashBoard()
        {
            InitializeComponent();   
            this.lstDashItems.DoubleClick += new System.EventHandler(this.lstDashItems_DoubleClick);
        }

        private void lstDashItems_DoubleClick(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }

            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString, conn);
            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            string patientId = lstDashItems.SelectedItems[0].SubItems["mpatientID"].Text;
            Patient pt = new Patient();
            pt.loadPatient(patientId);
            pt.Show();

        }

Now i have tried some code that figured by browsing the net. I get error : Object reference not set to an instance of an object.
I get in the line below:
string patientId = lstDashItems.SelectedItems[0].SubItems["mpatientID"].Text;
Can anyone please help me on how to solve this problem. Any help or guidance would be greatly appreciated.

specify column index instead of column name
if column index of "mpatientID" is 0 try like below
string patientId = lstDashItems.SelectedItems[0].SubItems[0].Text;

Sir/ Madam First of all thanks for replying to my query on such short notice .I just tried your solution just now and get error SqlException occured Conversion failed when converting the varchar value 'FamkePatient detail was added successfully' to data type int.
where Famke is name of patient .

 public void loadPatient(string mpatientID)
        {
            button1.Text = "Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString,conn);


            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            dataset = new DataSet();
            adp.Fill(dataset, "PATIENT_ID6");
            adp.Fill(dataset, "PATIENT_NAME6");
            adp.Fill(dataset, "ADDRESS7");
            adp.Fill(dataset, "PATIENT_CONTACT6");
            adp.Fill(dataset, "DOCTORDETAIL");

                dtDOB.DataBindings.Add("Text",dataset,"PATIENT_ID6.patient_dob");
                txtFname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_fname");
                txtMname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_mname");
                txtLname.DataBindings.Add("Text", dataset, "PATIENT_NAME6.patient_lname");
                cboSex.DataBindings.Add("Text", dataset, "PATIENT_ID6.patient_sex");
                cboVirology.DataBindings.Add("Text", dataset, "PATIENT_NAME6.virology");
                txtApartmentName.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_name");
                txtDoorNo.DataBindings.Add("Text", dataset, "ADDRESS7.door_number");
                txtStreet1.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_1");
                txtStreet2.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_2");
                txtStreet3.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_3");
                txtVillageArea.DataBindings.Add("Text", dataset, "ADDRESS7.village");
                txtCity.DataBindings.Add("Text", dataset, "ADDRESS7.city");
                txtState.DataBindings.Add("Text", dataset, "ADDRESS7.State");
                txtCountry.DataBindings.Add("Text", dataset, "ADDRESS7.country");
                txtApartmentNo.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_number");
                txtPostalCode.DataBindings.Add("Text", dataset, "ADDRESS7.pincode");
                txtHnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.homenumber");
                txtMnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.mobilenumber");
                cboDoctor.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_name");

        }

i get error in the lineadp.Fill(dataset,"PATIENT_ID6");
where PATIENT_ID6 is name of one of my tables in my database in sql server 2008.
Here is my full code.
In Mdi Parent form:

 public void updateUserActivities(long refID, int ActType, string ActivityStr)
        {

            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            SqlCommand cmd = new SqlCommand("Insert into USERACTIVITIES(user_id,row_upd_date,activity,type,ref_id)" + "Values(@user_id,GetDate(),@activity,@type,@ref_id)", conn);
            conn.Open();
            {
                cmd.Parameters.AddWithValue("@user_id", pUserID);
                cmd.Parameters.AddWithValue("@activity", ActivityStr);
                cmd.Parameters.AddWithValue("@type", ActType);
                cmd.Parameters.AddWithValue("@ref_id", refID);
                cmd.ExecuteNonQuery();
            }
            conn.Close();
        }

Patient form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class Patient : Form
    {
        long pUserID = 1;
        long patientID;
        string mpatientID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Patient()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString, conn);
            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            string SqlDataPull = ("Select doctor_first_name,doctor_last_name,doctor_middle_name from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id");
            SqlCommand cmd = new SqlCommand(SqlDataPull);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                SqlDataPull = dr[0].ToString()+dr[1].ToString()+dr[2].ToString();

                cboDoctor.Items.Add(SqlDataPull);
            }
            dr.Close();
        }


        private void Patient_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;
        }

        public void loadPatient(string mpatientID)
        {
            button1.Text = "Save";
            SqlConnection conn = new SqlConnection(conString);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString,conn);


            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            dataset = new DataSet();
            adp.Fill(dataset, "PATIENT_ID6");
            adp.Fill(dataset, "PATIENT_NAME6");
            adp.Fill(dataset, "ADDRESS7");
            adp.Fill(dataset, "PATIENT_CONTACT6");
            adp.Fill(dataset, "DOCTORDETAIL");

                dtDOB.DataBindings.Add("Text",dataset,"PATIENT_ID6.patient_dob");
                txtFname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_fname");
                txtMname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_mname");
                txtLname.DataBindings.Add("Text", dataset, "PATIENT_NAME6.patient_lname");
                cboSex.DataBindings.Add("Text", dataset, "PATIENT_ID6.patient_sex");
                cboVirology.DataBindings.Add("Text", dataset, "PATIENT_NAME6.virology");
                txtApartmentName.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_name");
                txtDoorNo.DataBindings.Add("Text", dataset, "ADDRESS7.door_number");
                txtStreet1.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_1");
                txtStreet2.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_2");
                txtStreet3.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_3");
                txtVillageArea.DataBindings.Add("Text", dataset, "ADDRESS7.village");
                txtCity.DataBindings.Add("Text", dataset, "ADDRESS7.city");
                txtState.DataBindings.Add("Text", dataset, "ADDRESS7.State");
                txtCountry.DataBindings.Add("Text", dataset, "ADDRESS7.country");
                txtApartmentNo.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_number");
                txtPostalCode.DataBindings.Add("Text", dataset, "ADDRESS7.pincode");
                txtHnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.homenumber");
                txtMnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.mobilenumber");
                cboDoctor.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_name");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            long patientID = 0;
            string dFieldName = "";
            Boolean vEmptyB=false;
            int vPatientID = 0;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "First Name should not be empty";

            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Sex should not be empty";
            }
            else if (cboVirology.SelectedIndex == -1)
            {
                vEmptyB=true;
                dFieldName = "Virology state of patient should not be empty";
            }
            else if (txtHnumber.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Home number of patient should not be empty";
            }
            if ((txtHnumber.Text.Length < 10) && (txtHnumber.Text.Length > 0))
            {
                vEmptyB = true;
                dFieldName = "Entered phone number was must have digits of ten numbersus which includes extension code also";
                txtHnumber.Focus();
            }

            else if (txtCity.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "City of patient should not be empty";
            }
            else if (txtCountry.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Country of patient should not be empty";
            }
            else if (cboDoctor.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Doctor Name should not be empty";
            }
            if (vEmptyB==true)
            {
                MessageBox.Show(dFieldName+"should not be empty");
                return;
            }


            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd = new SqlCommand("Insert into PATIENT_ID6(patient_sex,patient_dob,row_upd_date,user_id)" + "Values(@patient_sex,@patient_dob,GetDate(),@user_id)", conn);
            if (patientID == 0)
            {
                if (cboSex.SelectedIndex == 0)
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "M";
                }
                else
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "F";
                }

                cmd.Parameters.AddWithValue("@patient_dob", dtDOB.Value.ToString("dd-MMM-yyyy"));
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }
            if (patientID > 0)
            {
                cmd = new SqlCommand("update PATIENT_NAME6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into PATIENT_NAME6(patient_first_name,patient_middle_name,patient_last_name,virology,row_upd_date,status,user_id)" + "Values(@patient_first_name,@patient_middle_name,@patient_last_name,@virology,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@patient_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@patient_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@patient_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@virology", cboVirology.SelectedIndex);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if ((txtHnumber.Text != "") || (txtMnumber.Text != ""))
            {
                if (patientID > 0)
                {
                    cmd = new SqlCommand("Update PATIENT_CONTACT6 set status=false where patient_id=" + patientID);
                }
                cmd = new SqlCommand("Insert into PATIENT_CONTACT6(homenumber,mobilenumber,status,row_upd_date,user_id)" + "Values(@homenumber,@mobilenumber,@status,GetDate(),@user_id)", conn);
                cmd.Parameters.AddWithValue("@homenumber", txtHnumber.Text);
                cmd.Parameters.AddWithValue("@mobilenumber", txtMnumber.Text);
                cmd.Parameters.AddWithValue("@status", true);
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }

            if (patientID > 0)
            {
                cmd = new SqlCommand("Update ADDRESS7 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into ADDRESS7(apartment_name,door_number,street_name_1,street_name_2,street_name_3,village,city,state,country,row_upd_date,apartment_number,status,pincode,user_id)" + "Values(@apartment_name,@door_number,@street_name_1,@street_name_2,@street_name_3,@village,@city,@state,@country,GetDate(),@apartment_number,@status,@pincode,@user_id)", conn);
            cmd.Parameters.AddWithValue("@apartment_name", txtApartmentName.Text);
            cmd.Parameters.AddWithValue("@door_number", txtDoorNo.Text);
            cmd.Parameters.AddWithValue("@street_name_1", txtStreet1.Text);
            cmd.Parameters.AddWithValue("@street_name_2", txtStreet2.Text);
            cmd.Parameters.AddWithValue("@street_name_3", txtStreet3.Text);
            cmd.Parameters.AddWithValue("@village", txtVillageArea.Text);
            cmd.Parameters.AddWithValue("@city", txtCity.Text);
            cmd.Parameters.AddWithValue("@state", txtState.Text);
            cmd.Parameters.AddWithValue("@country", txtCountry.Text);
            cmd.Parameters.AddWithValue("@apartment_number", txtApartmentNo.Text);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@pincode", txtPostalCode.Text);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if (patientID > 0)
            {
                cmd = new SqlCommand("Update DOCTORPATIENT6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into DOCTORPATIENT6(doctor_id,row_upd_date,status,user_id)" + "Values(@doctor_id,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@doctor_id", cboDoctor.GetItemText(cboDoctor.SelectedIndex));
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();




            ((MDIParent5)this.MdiParent).updateUserActivities(vPatientID, 1, txtFname.Text + "Patient detail was added successfully");
            MessageBox.Show("Patient detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtHnumber_TextChanged(object sender, EventArgs e)
        {
            string s = txtHnumber.Text;
            Int32 result = 0;
            Int32.TryParse(s, out result);
            if (result == 0)
            {
                MessageBox.Show("Please enter phone number values", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


        }

        private void txtMnumber_TextChanged(object sender, EventArgs e)
        {
            string s =txtMnumber.Text;
            Int32 result = 0;
            Int32.TryParse(s, out result);
            if (result == 0)
            {
                MessageBox.Show("Please enter mobile number values", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }


    }
}

DashBoard form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class DashBoard : Form
    {
        long pUserID;
        private FormWindowState normal;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        public DashBoard()
        {
            InitializeComponent();   
            this.lstDashItems.DoubleClick += new System.EventHandler(this.lstDashItems_DoubleClick);
        }

        private void lstDashItems_DoubleClick(object sender, EventArgs e)
        {

            string patientId = lstDashItems.SelectedItems[0].SubItems[0].Text;
            Patient pt = new Patient();
            pt.loadPatient(patientId);
            pt.Show();

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DashBoard_Load(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            lstDashItems.Items.Clear();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            DataSet ds;
            SqlDataAdapter adp = new SqlDataAdapter();
            cmd = new SqlCommand("Select * from USERACTIVITIES where user_id=" + pUserID + "Order by row_upd_date desc", conn);
            adp = new SqlDataAdapter(cmd);
            ds = new DataSet();
            adp.Fill(ds, "USERACTIVITIES");
            dt = ds.Tables["USERACTIVITIES"];
            lstDashItems.Columns.Add("Task", 340, HorizontalAlignment.Left);
            lstDashItems.Columns.Add("Date", 492, HorizontalAlignment.Right);
            lstDashItems.View = View.Details;


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lstDashItems.Items.Add(dt.Rows[i].ItemArray[2].ToString());
                lstDashItems.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
            }




        }

Correct or guide me where have i gone wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.