Dear Sir,
I want to display two table values with where two condition
How to do this? Please help me sir.
Common Column: param_dept
Sample Data:
SELECT u.param_dsc, u.param_dept,u.param_rmrk,h.rd_two, h.entry_dt,h.param_dept
FROM m_param u
JOIN dly_prm_dta
WHERE h.param_dept= '" + Session["param_dept"] + "' AND h.entry_dt ='" + lblSelectedDate.Text + "'"
CREATE TABLE [dbo].[m_param] (
[Id] INT NOT NULL,
[param_cd] NCHAR (10) NULL,
[param_dsc] VARCHAR (50) NULL,
[param_dept] VARCHAR (50) NULL,
[param_rmrk] VARCHAR (100) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[dly_prm_dta] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Flw_mtr] VARCHAR (100) NULL,
[param_dept] VARCHAR (50) NULL,
[rd_one] NCHAR (300) NULL,
[rd_two] NCHAR (300) NULL,
[diff] NCHAR (300) NULL,
[rmk] VARCHAR (500) NULL,
[entry_by] VARCHAR (50) NULL,
[entry_dt] NCHAR (30) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespace ceodshb_nw
{
public partial class hmchp : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=ceo_dhbd;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
protected void Page_Load(object sender, EventArgs e)
{
Label3.Text = System.DateTime.Now.ToString("dd-MM-yyyy");
string encodedDate = Request.QueryString["date"];
string selectedDate = HttpUtility.UrlDecode(encodedDate);
lblSelectedDate.Text = selectedDate;
if (!this.IsPostBack)
{
this.BindData();
if (Session["emp_id"] == null)
Response.Redirect("lgn.aspx");
else
{
String EmplooyeId = Session["emp_id"].ToString();
Label1.Text = " " + EmplooyeId + "";
String param_dept = Session["param_dept"].ToString();
Label2.Text = "" + param_dept + " ";
// String dept = Session["dept"].ToString();
//Label3.Text = "" + dept + " ";
}
}
}
protected void BindData()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
// using (SqlCommand cmd = new SqlCommand("SELECT param_cd, param_dsc, param_dept,param_rmrk FROM m_param where param_dept='" + Label2.Text + "'", con))
// using (SqlCommand cmd = new SqlCommand("SELECT param_dsc, param_dept,param_rmrk FROM m_param where param_dept='" + Session["param_dept"] + "'", con))
//using (SqlCommand cmd = new SqlCommand("SELECT E.param_dsc, E.param_dept, D.rd_two,E.param_rmrk FROM m_param E, dly_prm_dta D WHERE E.param_dept = '" + Session["param_dept"] + "' AND E.entry_dt ='" + lblSelectedDate.Text + "'", con))
using (SqlCommand cmd = new SqlCommand("SELECT u.param_dsc, u.param_dept,u.param_rmrk,h.rd_two, h.entry_dt,h.param_dept FROM m_param u JOIN dly_prm_dta WHERE h.param_dept= '" + Session["param_dept"] + "' AND h.entry_dt ='" + lblSelectedDate.Text + "'", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
}
}
}
}