hi,
plz tell me how to get data from 3 different tables in sql. in this tables user id is unique,plz help me how to write the store procedure.
thanx
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.
Nilanka DharmadasaPosted Oct 28, 2009, 1:49 AM
It can happen due to one of the following reason.
1. Data set returned by the database is null. So report shows the dataset which was originally set at the creation of the report.
2. Dataset returned by database is not null. But this dataset doesnot support the report.
To trouble shoot this you can do the following.
For the first one , you can check it by debugging. If you don't know to debug, you can check it by adding this code block after getting datatble.
If you are sure that data table is not null, then the problem is in your crystal report.
If you pass your datatable from Sql server database, you must create your report in a way to suport Sql server database.
When you create the connection for report you should do it this way.
Create new connection > Select 'OLE DB(ADO)' > Select 'Microsoft Ole DB provider for SQL Server'
> Then click next
>Then give the server name, user name and password. (These details should match with the details you gave in the connection string used in the code.)
Then click finish.
Try this and let me know the outcome.
jimPosted Oct 27, 2009, 12:52 PM
roy himanshuPosted Oct 27, 2009, 8:51 AM
Nilanka DharmadasaPosted Oct 27, 2009, 8:45 AM
I have mistakenly typed
oRpt.SetDataSource(dt);
It should be corrected as follows,
cryrpt.SetDataSource(dt);
So the final answer is,
private void Form1_Load(object sender, EventArgs e)
{
Bom_Master_Update oj = new Bom_Master_Update();
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
cn.Open();
SqlCommand cmd = new SqlCommand("report1", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@column002", oj.comboBox1.Text);
//A data table is not returned by executenonquery method. So do it like this.
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd );
adapter.Fill(ds);
DataTable dt = ds.Tables[0];//dt contains your dataset.
cn.Close();
ReportDocument cryrpt = new ReportDocument();
cryrpt.Load(@"C:\Documents and Settings\Administrator\Desktop\COSTING cryst\costing\CrystalReport1.rpt");
cryrpt.DataSourceConnections.Clear();
cryrpt.SetDataSource(dt);
crystalReportViewer1.ReportSource = cryrpt;
crystalReportViewer1.Refresh();
}
Store procedure
ALTER PROCEDURE report1(@column002 varchar(30))
AS
BEGIN
select *from CATABLE003 where column001=(select column001 from CATABLE002 where column002=@column002)
END
In button click
private void Report_Click(object sender, EventArgs e)
{
Form1 obj = new Form1();
obj.Show();
}
If my answer helps you please accept my answer.
Nilanka DharmadasaPosted Oct 27, 2009, 8:38 AM
Change your code as follows.
private void Form1_Load(object sender, EventArgs e)
{
Bom_Master_Update oj = new Bom_Master_Update();
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
cn.Open();
SqlCommand cmd = new SqlCommand("report1", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@column002", oj.comboBox1.Text);
//A data table is not returned by executenonquery method. So do it like this.
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmd );
adapter.Fill(ds);
DataTable dt = ds.Tables[0];//dt contains your dataset.
cn.Close();
ReportDocument cryrpt = new ReportDocument();
cryrpt.Load(@"C:\Documents and Settings\Administrator\Desktop\COSTING cryst\costing\CrystalReport1.rpt");
cryrpt.DataSourceConnections.Clear();
oRpt.SetDataSource(dt);
crystalReportViewer1.ReportSource = cryrpt;
crystalReportViewer1.Refresh();
}
Store procedure
ALTER PROCEDURE report1(@column002 varchar(30))
AS
BEGIN
select *from CATABLE003 where column001=(select column001 from CATABLE002 where column002=@column002)
END
In button click
private void Report_Click(object sender, EventArgs e)
{
Form1 obj = new Form1();
obj.Show();
}
If my answer helps you please accept my answer.
roy himanshuPosted Oct 27, 2009, 8:25 AM
but i got all records in report view.but i want records of selected item in combobox.my code is past below.plz help me
private void Form1_Load(object sender, EventArgs e)
{
Bom_Master_Update oj = new Bom_Master_Update();
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
cn.Open();
SqlCommand cmd = new SqlCommand("report1", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@column002", oj.comboBox1.Text);
cmd.ExecuteNonQuery();
cn.Close();
ReportDocument cryrpt = new ReportDocument();
cryrpt.Load(@"C:\Documents and Settings\Administrator\Desktop\COSTING cryst\costing\CrystalReport1.rpt");
crystalReportViewer1.ReportSource = cryrpt;
crystalReportViewer1.Refresh();
}
Store procedure
ALTER PROCEDURE report1(@column002 varchar(30))
AS
BEGIN
select *from CATABLE003 where column001=(select column001 from CATABLE002 where column002=@column002)
END
In button click
private void Report_Click(object sender, EventArgs e)
{
Form1 obj = new Form1();
obj.Show();
}
Nilanka DharmadasaPosted Oct 26, 2009, 8:19 AM
This is the code you should write under your button click event.
Stored Procedure:
This is for SQL Server database.
If my answer helps you, please accept my answer. :)
naura paxPosted Oct 26, 2009, 6:32 AM
your combobox must contain one of the unique identifier as ValueMember. on buttonclick you can get selected items unique id.
int id=Conver.ToInt32(cmb.SelectedValue);
now you'll have to paas it into your stored procedure as variable @id-:
Select column1.... from aa inner join qq....
where aa.id=@id
in your Stored Procedure.
For details of how to create stored procedures please go through following link
http://msdn.microsoft.com/en-us/library/ms190669.aspx
and on how to call them in code you'll need to look for ADO.net on books online.
SreekanthPosted Oct 26, 2009, 6:31 AM
use:- union all
let a,b,c are three tables
then select* from a
union all
select * from b
union all
select * from c
where column name='SREEKANTH'
order by "some cloumn name"
...remebr * shuld be equl count and same type...
and ur order by sholud be in the last row...
http://www.w3schools.com/sql/sql_union.asp
roy himanshuPosted Oct 26, 2009, 6:22 AM
This is my 3 Tables
First Table=ffff
column001,column002,column003,column004
Second Table=gggg
column001,column002,column003,column004
Third Table=rrrr
column001,column002,column003,column004
in this tables column001 is unique identifier,my requirement is
when i select one item in combobox after click a button then the 3 tables data is
displayed ,how to write store procedure for my requirement plz help me
thanx
roy himanshuPosted Oct 26, 2009, 6:19 AM
This is my 3 Tables
First Table=ffff
column001,column002,column003,column004
Second Table=gggg
column001,column002,column003,column004
Third Table=rrrr
column001,column002,column003,column004
in this tables column001 is unique identifier,my requirement is
when i select one item in combobox after click a button then the 3 tables data is
displayed ,how to write store procedure for my requirement plz help me
thanx
Nilanka DharmadasaPosted Oct 26, 2009, 5:17 AM
This is the most simple query that we can write to get data from 3 tables named 'tableA', 'tableB' and 'tableC'. I have assumed that all three tables have a column named userid.
What is the database that you use? Because the syntax of the stored procedure may vary slightly, depending upon the database. Ex: Oracle, SQL server
If you can explin your requirement clearly, I can give you the xact query.
If my answer helps you, please accept my answer.
naura paxPosted Oct 26, 2009, 5:14 AM
suppose you have three tables
A Aid , name
B Aid, Bid, bname
C Bid, Cid,cname
we can write a query
Select A.Aid,A.name,B.Bid,B.bname,C.Cid,C.cname
from A inner join B on A.Aid=B.Aid
inner join C on B.Bid=C.Bid
is one example but if you give your table structure you can get better response.
bebo.