我正在使用薪资系统.我必须生成一份根据员工代码生成的报告 [英] i am working on payroll system.i have to genetare a report which is generated on employee code

查看:81
本文介绍了我正在使用薪资系统.我必须生成一份根据员工代码生成的报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工资系统上工作.我必须生成一份在员工代码上生成的报告.我正在发送我的代码.记录来自2个表,这就是为什么我在sql查询中使用别名的原因

这是代码:

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:

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;

}

推荐答案

在这里,您正在使用..
Here you are use..
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.....


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;



在这里,我尝试修改您的查询以执行INNER JOIN,这将有助于从您的表中获取完美的数据(如果任何列名错误),那么请进行修改并编写您自己的INNER JOIN查询......



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......


您没有提到哪个错误,但对我来说似乎是错误的查询.
我假设您在Salary表中也有emp_id字段.如果是这样,请尝试以下部分
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
from Emp_Join as j,Salary as s 
where j.emp_id=s.emp_id and s.emp_id = " + TextBox1.Text


或加入


or join

from Emp_Join join Salary on j.emp_id=s.emp_id 
where Salary.emp_id = " + TextBox1.Text


这篇关于我正在使用薪资系统.我必须生成一份根据员工代码生成的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆