I would like to ask a question about the following function related to reports in C#.
crystalReportViewer1.SelectionFormula = "{Cars.CarCode} = " + CarCode;
Does this formula add a filter condition to the current query code that is used in the report, or does it create a whole new query?
If not is there an other method of further filtering a report?
This will add a filter condition to the query. If carcode is a string you need to change it to :
crystalReportViewer1.SelectionFormula = string.Format("{Cars.CarCode} = '{0}'",CarCode);
Related
The grid-view that I have is filtered by some options and then it will be passed to a print program named "Stimulsoft" but when the filter is activated, the filtered records are not shown in the print page.
The code is shown below:
StiReport report = new StiReport();
tbldoreTableAdapter.Fill(doredataset.tbldore);
tbl_masolTableAdapter.Fill(doredataset.tbl_masol);
report.Load("Report.mrt");
report.RegData("DataSourc1", radGridView1.DataSource);
report.RegData(doredataset.tbldore);
report.RegData(doredataset.tbl_masol);
report.Show();
I need the filtered records to be shown in the print page.
You need to pass your query to the report before loading the report.
fisrt, define a variable (E.g. var1) in your report and change your dataset sql command as below:
select * from mytable {var1}
then in your code pass it like this:
StiReport1.Dictionary.Variables("Var1").Value = " where field1 = '" + TextBoxX1.Text + "'";
StiReport1.Compile();
StiReport1.Render();
StiReport1.Show();
P.S.: load your report in a "StiReport" object.
What I'm trying to do is a report bringing values of a table, but just if this table have specific selected client and others specific properties
Activation Report, follow a part of the code that already is working
var sql = "SELECT * FROM ativacao WHERE id_cliente = " + id_cliente;
var itemAtivacao = db.ativacao.SqlQuery(sql).ToList();
foreach (var item in itemAtivacao)
{
dt.Rows.Add(item.id, item.codigo, item.cliente.nome);
}
Until here Ok, easy. but I need to bring elements of table cliente, of other table comparing with a column. Damnt, it is boring.
Apart from the specifit client, I need to:
var id_executivo = Convert.ToInt32(Request.Form["id_executivo"]);
var id_prospector = Convert.ToInt32(Request.Form["id_prospector"]);
var id_cluster = Convert.ToInt32(Request.Form["id_cluster"]);
var id_status = Convert.ToInt32(Request.Form["id_status"]);
var id_cliente = Convert.ToInt32(Request.Form["id_cliente"]);
This is Columns of table Client. I'm thinking about INNER JOIN. is it???
summing up - I need to bring ativacoes of specific cliente if this cliente contains ......
Someone help me how can I do it please. Thanks so much.
I have an Excel sheet , I need to fetch two columns values - I have written a Linq query -
Error:
contextSwitchDeadLock was detected error at line
Query:
select new { Description = typeDescription.Description ,
VehicleKey = typeDescription.VehicleKey });
how can i fix this error - i want to fetch two coulmns value from the same Excel sheet , from a single linq Query.
I think its due to null values
try like this.
select new { Description = Convert.ToString(typeDescription.Description) ,
VehicleKey = Convert.ToString(typeDescription.VehicleKey) });
I'm new to writing LINQ queries, and I'm having trouble with string comparisons. I'm loading the data into a DataTable (confirmed that table in SQL DB and DataTable have same number of rows), but for some reason I can't find a value that I know exists in both.
The text box contains 'servername' while the datarows contain 'servername.mydomain.net', so here's what my code looks like
string strParameter = txtAutoComplete.ToString().ToLower();
//WUG TableAdapter and DataTable
dsCIInfoTableAdapters.DeviceTableAdapter taWUG;
taWUG = new dsCIInfoTableAdapters.DeviceTableAdapter();
dsCIInfo.DeviceDataTable dtWUG = new dsCIInfo.DeviceDataTable();
taWUG.Fill(dtWUG);
var qstWUG = (from row in dtWUG.AsEnumerable()
where row.Field<string>("sDisplayName").ToLower().Contains(strParameter)
select row.Field<string>("sDisplayName"));
Beleive in your LINQ statement dtWUG needs to be dtWUG.AsEnumerable(). Linq only works on data sources that implement the IEnumerable Interface.
You can debug it easier if you add some let statements where you can add breakpoints:
var qstWUG = (from row in dtWUG
let display = row.Field<string>("sDisplayName")
let lower = display.ToLower()
let contains = lower.Contains(strParameter)
where contains
select display).ToArray();
Also convert it to an array using .ToArray() at the end, will make it execute immediately (LINQ is lazy by paradigm, doesn't execute until it's needed), and also easier to look at in subsequent breakpoints.
Yeah, I feel stupid... I forgot to use the textbox.text to assign it to a string
string strParameter = txtAutoComplete.Text.ToLower();
//WUG TableAdapter and DataTable
dsCIInfoTableAdapters.DeviceTableAdapter taWUG;
taWUG = new dsCIInfoTableAdapters.DeviceTableAdapter();
dsCIInfo.DeviceDataTable dtWUG = new dsCIInfo.DeviceDataTable();
taWUG.Fill(dtWUG);
var qstWUG = (from row in dtWUG.AsEnumerable()
let display = row.Field<string>("sDisplayName")
where display.ToLower().Contains(strParameter)
select display).ToArray();
I am using a calculation in my SQL query. How can I use that calculated field in C#? When I try, I get an index out of range exception.
My query is:
Select OwnerCompanyLog.olog_name,inlt_companyid,inlt_childcompid,inlt_effectinterest,inlt_percent,inlt_sharetype,inlt_shares,inlt_childbase,inlt_effdate,
((inlt_percent * inlt_effectinterest)/100)eff
from InterestLogTable
INNER JOIN OwnerCompanyLog
ON
InterestLogTable.inlt_childcompid = OwnerCompanyLog.olog_companyid
where inlt_companyid=5
Order By inlt_childcompid
I want to use inlt_percent * inlt_effectinterest)/100 in my C# code:
entity.ParentCompany = new List<Company>();
while (parentCompanyReader.Read())
{
ParentCompany.Effect = parentCompanyReader["eff"].ToString();
entity.ParentCompany.Add(ParentCompany);
}
parentCompanyReader.Close();
But I got the error above.
the problem is only with calculated field. The above comment is absolutely correct. It could be your parentCompanyReader class that has the error. Meanwhile could you try few things to confirm the error.
Move the eff column to some middle. It could be that your parentCompanyReader would not be able to deal with only a limited number of column.
Also what is "eff" here, a column ? Also put a AS after the calculated column.
Select (inlt_percent * inlt_effectinterest)/100)eff AS EFF, OwnerCompanyLog.olog_name,inlt_companyid,inlt_childcompid,inlt_effectinterest,inlt_percent,inlt_sharetype,inlt_shares,inlt_childbase,inlt_effdate
Note : these are just arrows in dark !
Try to use it with index rather than column name .
while (parentCompanyReader.Read())
{
ParentCompany.Effect = Convert.ToInt32(parentCompanyReader[5]);
entity.ParentCompany.Add(ParentCompany);
}
parentCompanyReader.Close();
Im assuming that the calculated field returns an integer
and also make sure u use using statement so that incase if there is an error then connection will be closed and disposed