Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

Display Error message for unavailable record in Database.

$
0
0

Hai,

I'm Using VS 2010 and SQL server 2005.

I'm creating Salary slip report in my project. Its Successfully run.

See my code below.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillddl();
}
}


public void fillddl()
{
SqlConnection con = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=salaryReg;User ID=sa;Password=kavi");
con.Open();
SqlCommand com = new SqlCommand("select empName from SalaryEarnings ", con);
SqlDataReader dr = com.ExecuteReader();
ddlUserName.Items.Clear();
while (dr.Read())
{
ddlUserName.Items.Add(new ListItem(dr[0].ToString()));
}
ddlUserName.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}

protected void btnShow_Click(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dssample ds = new dssample(); // .xsd file name
DataTable dt = new DataTable();
dt.TableName = "Crstal Report";
dt = GetAllOrders();
ds.Tables[0].Merge(dt);
rptDoc.Load(Server.MapPath("~/CrystalReport.rpt"));

rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
}

public DataTable GetAllOrders()
{
SqlConnection cn = new SqlConnection("Data Source=SERVICETEAM-PC;Initial Catalog=salaryReg;User ID=sa;Password=kavi");
SqlCommand cmd = new SqlCommand("Select * from SalaryEarnings where empName='" + ddlUserName.Text + "' and Salary_Year='"+ddlSalaryYear.Text+"' and Salary_Month='"+ddlSalayMonth.Text+"'", cn);
DataSet ds = null;
SqlDataAdapter da;
try
{
cn.Open();
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds, "User");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (cn.State != ConnectionState.Closed)
cn.Close();
}
return ds.Tables[0];
}

From the Above code I got the report for the user selection.

The Problem is, If user select any unavailable record, it produce the report with the empty fields.

I don't want that, I need to produce Error message when the User select unavailable data.

If you know please help me.


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>