Hi!
I have a question but I would like to put some Delphi's codes maybe to understand very well. Even we are not in Delphi's forum here. I Apologise!
First my target is from a button to make a filter for some datas even all this datas filtered can be displayed on my dbgrid for example. But Its should be also displayed on my Crystal report page print preview (this is the matter I have).
In delphi, I used this for example:
//I filter data
myTable.Filter:= 'name=' +quotedstr(edit1.Text);
myTable.Filtered:= true;
//later on my print preview appear
QuickReport1.Preview;
Now, have a look on what I did on C#. But doesnt work:
private void Imprimir_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Luna_Agua_CS/Luna_Agua/Resources/CRFacturacao.rpt", "select * from facturacao ");
crystalReportViewer2.ReportSource = cryRpt;
crystalReportViewer2.Refresh();
}
Loading
Pravin GhadgePosted Jan 9, 2012, 10:50 AM
I have not completely undestood ur question.
U want to show report of particular gridview row. am i correct?
If yes then
After click on preview button u have to get rowindex of that gridview to find the name of gridviewrow.
For eg:
private void Imprimir_Click(object sender, EventArgs e)
{
string name=dbgrid.CurrentRow.Cells[0].Value.ToString();
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data source=.\\SQLEXPRESS;Integrated Security=True;database=ABC";
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from facturacao where name ='"+name+"'", con);
DataSet ds = new DataSet();
da1.Fill(ds);
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Luna_Agua_CS/Luna_Agua/Resources/CRFacturacao.rpt");
cryRpt..SetDataSource(ds.Tables[0]);
crystalReportViewer2.ReportSource = cryRpt;
crystalReportViewer2.Refresh();
}
Israel MfwambaPosted Jan 9, 2012, 6:13 AM
I have a form where I drop down firstly: an edit, two buttons (btnsearch and btnprintpreview) and a dbgrid.
Secondly, a have a dababase with 5 records:
Code Name | Age |
1 Roger 30
2 Steve 38
3 Mickael 33
4 Peter 45
5 Hellen 25
Now, when I introduce for example peter in my edit and click on my btnsearch. I can see from my dbgrid the record peter filtered (code nº4). For this part it's already done in my code.
Then, after doing my filter when I click on my second button btnprintpreview my crystal report page preview appear with all those five records with the peter's record filtered.
My target is not only on the WHERE sql's instruction but is focused on an edit where you can change introduce whatever name you want to search in your database.
I'm sure that now I'm clear. thank you.
Pravin GhadgePosted Jan 8, 2012, 12:25 AM
can u explain me wat do u mean by 'tedit'
Israel MfwambaPosted Jan 7, 2012, 1:03 PM
Please read me very well and you will understand what I'm talking about.
I already try it before to post for my question. My problem is about an Tedit putted on my form.
select * from facturacao where Name='Mickael'''
These instruction is about only when I click on my button. But now I would like to know when I write Mickael in my Tedit and click on my button what will happen? Because I need to change some time names: Jhon, Alice, Peter whatever. But using my Tedit.
Pravin GhadgePosted Jan 7, 2012, 11:06 AM
select * from facturacao where Name='Mickael'''
Israel MfwambaPosted Jan 7, 2012, 11:02 AM
but maybe I was wrong in my question. I would like to say that when a data is filled in an edit for example. then click on a button.
In the codes you send to me, I can only display all data once because there's a sql instruction ("select * from facturacao "). But not to do a specific data. Like for example (show me only Mickael).
Pravin GhadgePosted Jan 7, 2012, 10:44 AM
replace foll code:
private void Imprimir_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data source=.\\SQLEXPRESS;Integrated Security=True;database=ABC";
con.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from facturacao", con);
DataSet ds = new DataSet();
da1.Fill(ds);
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Luna_Agua_CS/Luna_Agua/Resources/CRFacturacao.rpt");
cryRpt..SetDataSource(ds.Tables[0]);
crystalReportViewer2.ReportSource = cryRpt;
crystalReportViewer2.Refresh();
}