i want to bind datas from two different tables into a single datagridview.Here i am using batch select query to get datas,and binding can be done using datareader or dataadapter.But i am getting datas from first table only.How can i bind datas from two tables here.Am attaching the code below.Help me please..
Thanks in advance.
public partial class Form1 : Form
private void bindgrid()
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=book;User ID=sa;Password=nest123@!");
SqlCommand cmd = new SqlCommand(@"select id,name,author,price from sale;select invc_id,totalprice from bill", con);
SqlDataAdapter sda=new SqlDataAdapter(cmd);
SqlCommandBuilder sc = new SqlCommandBuilder(sda);
DataTable dt = new DataTable("sale", "bill");
dataGridView1.DataSource = dt;
Couple of things here:
1. The second parameter is not DataTable.
2. What do you want to with the data tables, I see you are selecting 6 columns from 2 tables. Do you want to show six columns in the data grid? If so you will have to write a single query joining the tables, get the result set into single data table and bind to the grid.
22 Jan '13 - 21:57
If you want six columns in same query you can use Join between Sale and Bill table. It seems there is no relation between these two tabels. So You can Use the following query.
select sale.id,sale.name,sale.author,sale.price,bill.invc_id, bill.totalprice from sale, bill
22 Jan '13 - 22:04
Edited 22 Jan '13 - 22:08
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)