我需要以编程方式显示数据,但我的代码总是显示相同的数据。即使我更改 WHERE em.emp_id=5 或 6 也一样
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlConnection c = frmMain.connect();
rptEmpProf cryRpt = new rptEmpProf();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
crConnectionInfo.ServerName = frmMain.dbSrvrName;
crConnectionInfo.DatabaseName = frmMain.dbName;
crConnectionInfo.UserID = frmMain.dbUsrName;
crConnectionInfo.Password = frmMain.dbPass;
CrTables = cryRpt.Database.Tables ;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
string q = "SELECT em.emp_id 'Employee ID', " +
"em.emp_fname 'First Name', " +
"em.emp_lname 'Last Name', " +
"em.emp_phone 'Phone', " +
"em.emp_email 'Email', " +
"em.emp_addr 'Address', " +
"em.emp_join_dt 'Join Date', " +
"em.emp_salary 'Salary'," +
"em.emp_card_no 'Card No.', " +
"ds.dsg_name 'Designation', " +
"dp.dept_name 'Department', " +
"sf.sft_name 'Shift', " +
"sc.sec_name 'Section' " +
"FROM employee em INNER JOIN designations ds ON ds.dsg_id=em.emp_dsg_id " +
"INNER JOIN sections sc ON sc.sec_id = ds.dsg_sec_id " +
"INNER JOIN departments dp ON dp.dept_id = sc.sec_dept_id " +
"INNER JOIN shifts sf ON sf.sft_id = em.emp_sft_id " +
"WHERE em.emp_id = 6;";
SqlCommand cmd = new SqlCommand(q, c);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
cryRpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
frmMain.disconnect(c);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
this.Close();
}
}