SAP Crystal Report : Subreport not showing data in production - crystal-reports

I have a main report and 5 subreports, everything is working well except 1 subreport.
In development mode when I preview the main report all the subreports showing data perfectly, especially the subreport "Symptom/s" is fine:
But in production mode, the subreport "Symptom/s" is not coming:
private void loadReport(Int64 appointmentID)
{
try
{
rd = new ReportDocument();
//For main patient record
SqlCommand cmd1 = new SqlCommand("st_getPatientBill", MainClass.con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
rd.Load(Application.StartupPath + "\\Reports\\PrescriptionReport.rpt");
rd.SetDataSource(dt1);
ConnectionInfo ci = new ConnectionInfo();
ci.DatabaseName = "cms";
ci.UserID = "sa";
ci.Password = "12345";
ci.ServerName = "DESKTOP-753VMJS";
Tables tables = rd.Database.Tables;
SqlCommand cmd4 = new SqlCommand("st_getInternalMedicine", MainClass.con);
cmd4.CommandType = CommandType.StoredProcedure;
cmd4.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da4 = new SqlDataAdapter(cmd4);
DataTable dt4 = new DataTable();
da4.Fill(dt4);
rd.Subreports[0].SetDataSource(dt4);
//For external medicine
SqlCommand cmd3 = new SqlCommand("st_getExternalMedicine", MainClass.con);
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataTable dt3 = new DataTable();
da3.Fill(dt3);
rd.Subreports[0].SetDataSource(dt3);
//For disease
SqlCommand cmd5 = new SqlCommand("st_getPatientDiseaseWRTAppointment", MainClass.con);
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da5 = new SqlDataAdapter(cmd5);
DataTable dt5 = new DataTable();
da5.Fill(dt5);
rd.Subreports[0].SetDataSource(dt5);
//For symptoms
SqlCommand cmd6 = new SqlCommand("st_getPatientSymptomsWRTAppointment", MainClass.con);
cmd6.CommandType = CommandType.StoredProcedure;
cmd6.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da6 = new SqlDataAdapter(cmd6);
DataTable dt6 = new DataTable();
da6.Fill(dt6);
rd.Subreports[0].SetDataSource(dt6);
//For tests
SqlCommand cmd7 = new SqlCommand("st_getPatientTestWRTAppointment", MainClass.con);
cmd7.CommandType = CommandType.StoredProcedure;
cmd7.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da7 = new SqlDataAdapter(cmd7);
DataTable dt7 = new DataTable();
da7.Fill(dt7);
rd.Subreports[0].SetDataSource(dt7);
//For internal medicine
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = ci;
table.ApplyLogOnInfo(tableLogonInfo);
}
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.RefreshReport();
}
catch (Exception ex)
{
if (rd != null)
{
rd.Close();
}
}
}
The details are above

I can recommend checking the following:
a) try to find all tables, objects in the report which don't work
(specially try to connect the subreport to different development server in design time it will unveil you hidden dependency of objects in the subreport
b) don't forget to reimport the subreport after you finished any updates :)
b) try to connect all table objects by the following procedure:
(apply it on main report (_reportDocument)
CrystalDecisions.Shared.TableLogOnInfo tableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();
tableLogOnInfo.ConnectionInfo.ServerName = this.DbServer;
tableLogOnInfo.ConnectionInfo.DatabaseName = this.DbCatalog;
tableLogOnInfo.ConnectionInfo.Password = this.DbPassword;
tableLogOnInfo.ConnectionInfo.UserID = this.DbUser;
tableLogOnInfo.ConnectionInfo.IntegratedSecurity = this.DbIntegratedSecurity;
foreach (Table tbl in _reportDocument.Database.Tables)
{
tbl.ApplyLogOnInfo(tableLogOnInfo);
}
foreach (Section sec in _reportDocument.ReportDefinition.Sections)
{
foreach (ReportObject obj in sec.ReportObjects)
{
if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
string subDocName = ((SubreportObject)obj).SubreportName;
ReportDocument subDoc = ((SubreportObject)obj).OpenSubreport(subDocName);
foreach (Table tbl in subDoc.Database.Tables)
{
tbl.ApplyLogOnInfo(tableLogOnInfo);
}
}
}
}
P.

Related

Why crystal report prompting me for parameter field value while I have written code for it

Why crystal report prompting me for parameter field value while I have written code for it.
Private void ReportVeiwer_Load(object sender, EventArgs e)
{
ReportDocument reportdoc = new ReportDocument();
///string invoice_number = (;
Invoice invoicerpt = new Invoice();
ParameterField paramfield = new ParameterField();
ParameterFields paramfields = new ParameterFields();
paramfield.Name = "Invoice_Number";
ParameterDiscreteValue dicval = new ParameterDiscreteValue();
dicval.Value = User_Info.invoice_number;
paramfield.CurrentValues.Add(dicval);
paramfields.Add(paramfield);
ReportVeiwer rptveiwer = new ReportVeiwer();
rptveiwer.crystalReportViewer1.ParameterFieldInfo = paramfields;
reportdoc.Load(#"D:\Furqan\SchoolManagementSystem\SchoolManagementSystem\Invoice.rpt");
crystalReportViewer1.ReportSource = reportdoc;
reportdoc.SetDatabaseLogon("PC-Name/User", "Password", ".", "Database");
}
Load the report first. Then, set the parameter value...

How do I use Entity Framework instead of Ado.net for stored procedure?

I am using a stored procedure in my SQL Server database to take input of the data through the datatable. As I am using ASP.NET MVC now, I want to use Entity Framework instead of ado.net
public void BulkUpload(DataTable dt)
{
dt.TableName = "MainTable";
DataSet dataset = new DataSet();
DataTable dataTable = new DataTable();
try
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
{
conn.Open();
{
SqlCommand cmd = new SqlCommand("DatatableToDataBase", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#mode", SqlDbType.VarChar).Value = "MainTB";
cmd.Parameters.AddWithValue("#Details", SqlDbType.VarChar).Value = dt;
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
catch (Exception)
{ }
}
It's very easy just add an entity datamodel to your program
connect to you model :
"entitymodel" context = this.CurrentDataSource;
And pass the stored procedure where you like .
Thats everything
Example:
[WebGet]
public List<callersW> GetCaller()
{
testCDREntities1 context = this.CurrentDataSource;
//sql parameters here
List<callersW> result = context.Database.SqlQuery<callersW>("StoredProcedure").ToList();
return result;
}

Crystal Report doesn't show data when generated

When I generate it on runtime, it doesn't show any data. But it does when I check on the 'Main Report Preview' of VS 2010. I have also checked my stored procedure, it does produce data when I execute it. What seems to be the problem?
This is my code in page_load:
protected void Page_Load(object sender, EventArgs e)
{
string municipio = Request.QueryString["municipio"];
string ano = Request.QueryString["ano"];
string cnpj = Server.UrlDecode(Request.QueryString["cnpj"]);
DataTable dt;
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection cnn = new SqlConnection(CS))
{
cnn.Open();
//stored procedure
SqlCommand cmd = new SqlCommand("spConsultaRelatorioCompleto", cnn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#ano", ano);
cmd.Parameters.AddWithValue("#municipio", municipio);
cmd.Parameters.AddWithValue("#cnpj", cnpj);
//read access to the database
SqlDataReader dr = cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(cmd);
//datatable with data
dt = new DataTable("dt");
//datatable with datareader's data
dt.Load(dr);
da.Fill(dt);
}
ReportDocument MeuRelatorio = new ReportDocument();
MeuRelatorio.Load(Server.MapPath("RelatorioConvenio.rpt"));
MeuRelatorio.SetDataSource(dt);
CrystalReportViewer1.ReportSource = MeuRelatorio;
}
}
}
I give some values in another webform when I click the button below:
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Redirect("RelatorioGerado.aspx?municipio=" + ddlmunicipioconvenente.Text + "&cnpj=" + Server.UrlEncode(tbcnpjconvenente.Text) + "&ano=" + tbAno.Text);
}

RuntimeBinderException: Convert type System.Threading.Tasks.Task<object> to string

I do an example with signalR. But it doesn't function because of one mistake.
The one mistake (can not convert type system.threading.tasks.task< object> to string) is in this line:
return context.Clients.All.RecieveNotification(simple);
It is at the bottom of the code you can see below.
Below you see the method I wrote. There I do a connection with the database and get the content with a command/query.
Then a few checks and also SqlDependency.
public string SendNotifications()
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
{
string query = "SELECT eintrag FROM [dbo].[simple_column]";
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
DataTable dt = new DataTable();
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
var reader = command.ExecuteReader();
dt.Load(reader);
if (dt.Rows.Count > 0)
{
simple = dt.Rows[0]["eintrag"].ToString();
}
}
}
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
return context.Clients.All.RecieveNotification(simple);
}
And here I use the function:
var notifications = $.connection.notificationHub;
notifications.client.recieveNotification = function (simple) {
// Add the message to the page.
$('#dbMessage').text(simple);
};
I hope you can help me.
Thanks.

ORA-06550 , wrong number or types of arguments in call to Oracle Stored Procedure

I have a stored procedure which has one in parameter and one out parameter as follows:
create or replace procedure worker_name (w_id in number, w_first out worker.first_name%type) is
Begin
select first_name into w_first
from worker
where worker_id = w_id;
end;
Code to call this stored procedure:
public DataTable <b>GetEmployeeName</b>(int _employeeID)
{
ArrayList arrEmployeeName = new ArrayList();
OracleParameter paramEmployeeId = new OracleParameter(":employeeid", _employeeID);
arrEmployeeName.Add(paramEmployeeId);
DataLayer obj = new DataLayer();
DataTable tblEmployee = obj.<b>GetData</b>("macw_conv.worker_name", arrEmployeeName, "SP");
if (tblEmployee.Rows.Count > 0)
{
return tblEmployee;
}
return null;
}
public DataTable <b>GetData</b>(string query, ArrayList parameters,string queryType)
{
//DataTable dt = new DataTable();
try
{
_con =
new OracleConnection(Oradb);
_con.Open();
_cmd = new OracleCommand(query, _con);
if (_cmd.Connection.State == ConnectionState.Open)
{
if (queryType == "SP" && parameters != null)
{
_cmd.CommandType = CommandType.StoredProcedure;
if (parameters.Count > 0)
{
foreach (OracleParameter param in parameters)
{
_cmd.Parameters.Add(param);
}
}
}
}
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(_cmd);
da.Fill(ds);
if (ds.Tables.Count > 0)
{
return ds.Tables[0];
}
return null;
}
I guess I'm unable to see the obvious error. It's something about the data type mismatch between the out parameter in the stored procedure and output parameter in the code. Any kind of help is appreciated.
Thanks!
I figured out the issue: it was because the datatype of the variable that is saving the out parameter was not handled properly. I changed the code as follows:
try
{
_con = new OracleConnection(Oradb);
_cmd = _con.CreateCommand();
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.CommandText = "macw_conv.worker_name";
OracleParameter inobj1 = _cmd.Parameters.Add("w_id", OracleDbType.Int32,50);
inobj1.Direction = ParameterDirection.Input;
inobj1.Value = _employeeID;
OracleParameter inobj2 = _cmd.Parameters.Add("w_last", OracleDbType.Int32, 50);
inobj2.Direction = ParameterDirection.Input;
inobj2.Value = String.IsNullOrEmpty(_lastName) ? null : _lastName;
OracleParameter outobj = _cmd.Parameters.Add("w_first", OracleDbType.Varchar2, 50);
outobj.Direction = ParameterDirection.Output;
_con.Open();
_cmd.ExecuteNonQuery();
_employeeName = ((OracleString) _cmd.Parameters[1].Value).ToString();
_cmd.Dispose();
_con.Close();
}
catch (OracleException ex)
{
Console.WriteLine(ex.Message);
}
return _employeeName;
Try
public DataTable GetEmployeeName(int _employeeID)
{
ArrayList arrEmployeeName = new ArrayList();
OracleParameter paramEmployeeId = new OracleParameter("employeeid", _employeeID);
arrEmployeeName.Add(paramEmployeeId);
OracleParameter paramEmployeeFirst = new OracleParameter("first", OracleDbType.Varchar2, ParameterDirection.Output);
arrEmployeeName.Add(paramEmployeeFirst);
DataLayer obj = new DataLayer();
DataTable tblEmployee = obj.GetData("macw_conv.worker_name(:1,:2)", arrEmployeeName, "SP");
if (tblEmployee.Rows.Count > 0)
{
return tblEmployee;
}
return null;
}