Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am working on payroll system.i have to genetare a report which is generated on employee code.i am sending my code.record is coming from 2 table thats why i am using alias in sql quries

Here is the code:

C#
if (TextBox1.Text != "")
{
    sqlconnet = new SqlConnection("Data Source=.;Initial Catalog=Pay_Roll;Integrated Security=True");
    sqlconnet.Open();
    SqlCommand sqlcommand=new SqlCommand("select j.full_name,s.rate,s.Month_s,s.Year_s,s.Days_Att,s.Basic_Salary,s.DA,s.HRA,s.Conveyance,s.WA,s.T_Amt,s.ESI,s.PF,s.LWF,s.TDS,s.Deduction,s.Net_pay from Emp_Join as j,Salary as s where j.emp_id=s."+TextBox1.Text,sqlconnet);
    string s = (string)sqlcommand.ExecuteScalar();
    ds = new DataSet(s);
    indivisual.Load(Server.MapPath("IndivisualReport.rpt"));
    indivisual.SetDataSource(ds);
    CrystalReportViewer1.ReportSource = indivisual;

}
Posted
Updated 3-Nov-11 19:56pm
v3
Comments
Tejas Vaishnav 4-Nov-11 1:53am    
From where you got the error....
prakash00060 4-Nov-11 2:03am    
Incorrect syntax near '.10003'.
this is the error
10003 is emp_id.
Tejas Vaishnav 4-Nov-11 1:56am    
Editing Content as well as tags....
prakash00060 4-Nov-11 2:03am    
Incorrect syntax near '.10003'.
this is the error
10003 is emp_id.
Uday P.Singh 4-Nov-11 1:58am    
and your question is..

Here you are use..
C#
sqlcommand.ExecuteScalar();


menas you need only first colum from first row of you resulted data...

so why you use many columns in your query....


If you need to fill you dataset with your resulted data you need to do something like this..... no the way you do.....


C#
SqlConnection cs = new SqlConnection("YOU CONNECTION STRING");
SqlDataAdapter da = new SqlDataAdapter();
string query = "select j.full_name,s.rate,s.Month_s,s.Year_s,s.Days_Att,s.Basic_Salary,s.DA,s.HRA,s.Conveyance,s.WA,s.T_Amt,s.ESI,s.PF,s.LWF,s.TDS,s.Deduction,s.Net_pay from Emp_Join as j INNER JOIN Salary as s ON j.emp_id = s.emp_id WHERE j.emp_id = " + TextBox1.Text;
da.SelectCommand = new SqlCommand(query, cs);
DataSet ds = new DataSet();
da.Fill(ds);
indivisual.Load(Server.MapPath("IndivisualReport.rpt"));
indivisual.SetDataSource(ds);
CrystalReportViewer1.ReportSource = indivisual;


here i have tried to modify you query to perform INNER JOIN that will help to get perfect data from you table if any column name are wrong then please modify that and write your own INNER JOIN query......
 
Share this answer
 
Comments
Vikas_Shukla_89 4-Nov-11 2:32am    
my +5
You didn't mention which error, but seems like wrong query to me.
I assume that you have emp_id field in Salary table also. If so, try the following part
SQL
from Emp_Join as j,Salary as s 
where j.emp_id=s.emp_id and s.emp_id = " + TextBox1.Text

or join
SQL
from Emp_Join join Salary on j.emp_id=s.emp_id 
where Salary.emp_id = " + TextBox1.Text
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900