ASSALAM-O-ALIKUM BROTHRS N SISTRER;
ABOUT MY REQUIREMENT:
MY REQUIREMENT IS, I WANT TO GET DATA OF "PATIENT SURGERY" N "SURGERY" IN "MAIN SURGERY TABLE". I AM ALSO SENDING MY TARGET FIGURE FOR UNDERSTANDING OF MY NEEDS. IN THE BELOW, I MENTIONED MY CODE. IN THIS I USED JOIN QUERY . BUT THE PROBLEM IS MY DATA IS NOT DISPLAY IN THE GRID.
public void load_grid()
{ SqlCommand cmd = new SqlCommand("select s.[surgery id],s.[patient surgery id],s.[surgery name],s.[surgery type id],s.[type name],s.[charges],s.[pv id],s.[patient visit charges] from clinicMainsurgery s inner join surg su on su.[surgery id]=s.[surgery id] inner join patientsurgery ps on ps.[patient surgery id]=s.[patient surgery id]");
cmd.Connection = Connection.get();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.SelectCommand = cmd;
da.Fill(ds);
GridView_surgery.DataSource = ds;
GridView_surgery.DataBind();
}
protected void Button_sugeries_Click(object sender, EventArgs e)
{
load_grid();
}
Loading

Satyapriya NayakPosted Dec 19, 2011, 10:02 AM
Run the attachments.
No need to create mainsurgery table.You create a relation in surg and patientsurgery table.
Add a column as patient surgery id in surg table.
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="surgery.aspx.cs" Inherits="Gridview_joins.surgery" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_joins
{
public partial class surgery : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
load_grid();
}
protected void Btn_add_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "insert into [surg]([surgery id],[patient surgery id],[surgery name],[charges],[type id],[type name])values('" + TextBox_surgery_id.Text + "','" + TextBox_patient_surgery_id.Text + "','" + DropDownList_surgery_name.Text + "','" + TextBox_surgery_charges.Text + "','" + DropDownList_surgery_type_id.SelectedItem.Text + "','" + DropDownList_surgery_type_name.SelectedItem.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
load_grid();
}
public void load_grid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from [surg]";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.SelectCommand = com;
sqlda.Fill(ds);
GridView_show_surgery.DataSource = ds;
GridView_show_surgery.DataBind();
}
protected void btn_show_Click(object sender, EventArgs e)
{
load_grid();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="patient_surgery.aspx.cs" Inherits="Gridview_joins.patient_surgery" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_joins
{
public partial class patient_surgery : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
load_grid();
}
protected void Btn_add_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "insert into [patientsurgery]([patient surgery id],[pv id],[patient charges])values('" + TextBox_patient_surgery_id.Text + "','" + TextBox_pv_id.Text + "'," + TextBox_patient_charges.Text + ")";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
load_grid();
}
protected void Btn_show_Click(object sender, EventArgs e)
{
load_grid();
}
public void load_grid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from [patientsurgery]";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.SelectCommand = com;
sqlda.Fill(ds);
GridView_patient_surgery.DataSource = ds;
GridView_patient_surgery.DataBind();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Gridview_joins._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_joins
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
public void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = str = "select s.[surgery id],s.[patient surgery id],s.[surgery name],s.[charges],s.[type id],s.[type name],p.[pv id],p.[patient charges] from surg s inner join patientsurgery p on s.[patient surgery id]=p.[patient surgery id]";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.SelectCommand = com;
sqlda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}
}
Thanks
sumaira manzoor hussain khanPosted Dec 19, 2011, 1:21 AM
i am sending my complete database file(code,erd,requirement diagram,db file).
regards
sumaira manzoor
Satyapriya NayakPosted Dec 18, 2011, 9:21 AM
There might not have any records in clinicMainsurgery table.
Can you please send me the tables with records.
Thanks
Pravin GhadgePosted Dec 18, 2011, 7:43 AM
Replace inner join to Left outer join.
& then check the result