Dear Sir,
I have 3 tables like tableA, tableB and tableC how to add tableA+tableB=tableC and result will show in gridview
format using C# or Sql server
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 13, 2011, 11:18 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
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;
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();
}
}
void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
//str = "select customer.custid,customer.custname,customer.custaddress,product.prodname,product.prodprice from customer, product where customer.prodid = product.prodid";
str = "select cust.custid,cust.custname,cust.custaddress,prod.prodname,prod.prodprice FROM customer cust INNER JOIN product prod ON cust.prodid = prod.prodid";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "customer");
GridView1.DataSource = ds;
GridView1.DataMember = "customer";
GridView1.DataBind();
con.Close();
}
}
Thanks