ASSALAM-O-ALIKUM TO ALL OF YOU;
SIR, MY QUESTION IS "HOW WE CAN GET DATA FROM MULTIPLES TABLE IN ONE FORM USING C#". FOR EXAMPLE, I HAVE THREE DIFFERENT TABLES ONE IS SURGERY(SURGERY ID,SURGERY NAME, CHARGES, SURGERY TYPE ID), SECOND IS SURGERY TYPE(SURGERY TYPE ID, SURGERY TYPE NAME), THIRD IS PATIENT SURGERY(SURGERY ID,PATIENT VISIT ID,CHARGES). SO I WANT DATA OF THESE TABLES IN MY MAIN SURGERY FORM.
REGARDS
SUMAIRA MANZOOR
Loading


Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 15, 2011, 9:21 AM EST
Run the attachments.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Gridview_three_columns._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_three_columns
{
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)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "Select s.[SURGERY ID],s.[SURGERY NAME],s.CHARGES,st.[SURGERY TYPE ID],st.[SURGERY TYPE NAME],ps.[PATIENT VISIT ID],ps.CHARGES From SURGERY s inner join SURGERYTYPE st on st.[SURGERY TYPE ID] = s.[SURGERY TYPE ID] inner join PATIENTSURGERY ps on ps.[SURGERY ID] = s.[SURGERY ID]";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}
}
Thanks
Pravin MoreRank #1,419 · 1.2K reputationPosted Dec 14, 2011, 7:59 PM EST
hi sumaira,
do this by executing this below query from your code...
select ps.PatientvisutID,s.SurgeryName,ps.Charges,st.Surgerytypename
from SURGERY s (nolock) join
surgeryType st (nolock) on s.surgerytypeID=st.surgerytypeID
join PatientSurgery ps (nolock) on ps.surgeryID=s.surgeryID
Note:-change columns in select query according to you need
Thanks,
Pravin.
Datta KharadRank #2,135 · 668 reputationPosted Dec 14, 2011, 9:00 PM EST
sSQL="Select s.SurgeryName, s.Charges, st.SurgeryTypeName, ps.PatientVisitId, ps.Charges From SURGERY s INNER JOIN SURGERYTYPE st on s.SurgeryTypeId=st.SurgeryTypeId JOIN PATIENTSURGERY ps on s.SurgeryId=ps.SurgeryId";
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Dec 15, 2011, 12:12 AM EST
why, you used ps,st and so on. is it a property.
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 15, 2011, 12:46 AM EST
Those are aliases
There are two types of aliases that are used most frequently: column alias and table alias.
Please refer the below link
http://www.1keydata.com/sql/sqlalias.html
Thanks
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Dec 15, 2011, 1:31 AM EST
can you elaborate your code. because i am not getting ur answer
Vilas GiteRank #951 · 2.1K reputationPosted Dec 15, 2011, 3:08 AM EST
Hi Mam
Please refer for more details
http://www.java2s.com/Code/SQL/Join/JOINthreetableswithconditions.htm
Thanks!
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Dec 15, 2011, 3:54 AM EST
is it necessary we use store procedure with join query. we can use simple statement with join query. sir, my requirement is : i want to get data from multiple tables in one table using csharp. store procedure with join or simple statement with join can fullfil my requirement or not.
Prabhu RajaRank #861 · 2.6K reputationPosted Dec 15, 2011, 4:58 AM EST
Hope this Will help you.
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Dec 15, 2011, 9:11 PM EST
this is a good answer. but sir i want to know you wrote s.[SURGERY ID],s.[SURGERY NAME],s.CHARGES. and so on. sir, is it a store procedure . can you explain how we can use this.
regards
sumaira manzoor
sumaira manzoor hussain khanRank #8,900 · 214 reputationPosted Dec 16, 2011, 11:13 AM EST
there is error occur in my code. can you check my code . i am sending a screen shot.
Arjun DhilodRank #2,044 · 708 reputationPosted Feb 21, 2014, 1:25 AM EST
SELECT SURGERY.SURGERY ID, SURGERY.SURGERY NAME,SURGERY.CHARGES,SURGERY TYPE.SURGERY TYPE NAME
SURGERY TYPE ID
FROM SURGERY
INNER JOIN SURGERY TYPE
ON SURGERY.SURGERY TYPE ID=SURGERY TYPE.SURGERY TYPE ID;