problem in generating crysatl reports
-
Hello Every body, I am new with crystal reports. I want to generate report for those employees whose age is more than 50 yrs. But I am not able to do so .It is showing all the records. I had added an crystal report in my project. I link it with the database through wizard only, On form1 it had inserted an crystal report viewer. on the load event of the form1 I had used the following code but it is use less. SqlConnection Connection = new SqlConnection("server='server1'; user id='sa'; password='admin'; database='employee'"); SqlCommand myCommand = new SqlCommand("SELECT * from companyEmp where age < '50'"); myCommand.Connection = Connection; myCommand.CommandType = CommandType.Text; SqlDataAdapter DA = new SqlDataAdapter(); DA.SelectCommand = myCommand; DataSet DS = new DataSet(); DA.Fill(DS); crystalReportViewer1.SetDataSource(DS.Tables[0]); crystalReportViewer1.ReportSource = objNewReport; But it is still showing all the record of companyEmp. Regards, rahul saini
-
Hello Every body, I am new with crystal reports. I want to generate report for those employees whose age is more than 50 yrs. But I am not able to do so .It is showing all the records. I had added an crystal report in my project. I link it with the database through wizard only, On form1 it had inserted an crystal report viewer. on the load event of the form1 I had used the following code but it is use less. SqlConnection Connection = new SqlConnection("server='server1'; user id='sa'; password='admin'; database='employee'"); SqlCommand myCommand = new SqlCommand("SELECT * from companyEmp where age < '50'"); myCommand.Connection = Connection; myCommand.CommandType = CommandType.Text; SqlDataAdapter DA = new SqlDataAdapter(); DA.SelectCommand = myCommand; DataSet DS = new DataSet(); DA.Fill(DS); crystalReportViewer1.SetDataSource(DS.Tables[0]); crystalReportViewer1.ReportSource = objNewReport; But it is still showing all the record of companyEmp. Regards, rahul saini
monuSaini wrote:
SqlCommand myCommand = new SqlCommand("SELECT * from companyEmp where age < '50'");
U just need:
SqlCommand("SELECT * from companyEmp where age < **50**");
'50' -> type string 50 -> int Regard, Edwin -
monuSaini wrote:
SqlCommand myCommand = new SqlCommand("SELECT * from companyEmp where age < '50'");
U just need:
SqlCommand("SELECT * from companyEmp where age < **50**");
'50' -> type string 50 -> int Regard, Edwin -
Hello Edwin, Thanks for ur rply. But still same problem. It is showing all the records. If I am using only this crystalReportViewer1.ReportSource = NewReport; then also it is showing all the records. Rregards, rahul saini
-
Hello Edwin, Thanks for ur rply. But still same problem. It is showing all the records. If I am using only this crystalReportViewer1.ReportSource = NewReport; then also it is showing all the records. Rregards, rahul saini
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet(); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ds.WriteXml("C:\text.xml");
Then On your crystal report Database Fields: change your dataset with "text.xml" If U have finish it, then create a dataset with your query, then change the code like this:
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet("YourDataSet"); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ReportDocument rd = new ReportDocument(); rd.SetDataSource = ds; crystalReportViewer1.ReportSource = rd;
Regard, Edwin
-
Hi Rahul, I wonder if u want to show the data if the age is above 50 right? if u use query:
SELECT * FROM Your_Table Where age < 50
u got an output data age below 50, if u want to show the data where age is more than 50 than u must change your query into :SELECT * FROM Your_Table WHERE age > 50
i try to my query analizer thats work:) Regard, Tomi -
Hi Rahul, I wonder if u want to show the data if the age is above 50 right? if u use query:
SELECT * FROM Your_Table Where age < 50
u got an output data age below 50, if u want to show the data where age is more than 50 than u must change your query into :SELECT * FROM Your_Table WHERE age > 50
i try to my query analizer thats work:) Regard, TomiTomiEdy wrote:
if u use query: SELECT * FROM Your_Table Where age < 50 u got an output data age below 50, if u want to show the data where age is more than 50 than u must change your query into : SELECT * FROM Your_Table WHERE age > 50
I think U right Tomi, maybe U must check your query Rahul Regard, Edwin
-
TomiEdy wrote:
if u use query: SELECT * FROM Your_Table Where age < 50 u got an output data age below 50, if u want to show the data where age is more than 50 than u must change your query into : SELECT * FROM Your_Table WHERE age > 50
I think U right Tomi, maybe U must check your query Rahul Regard, Edwin
-
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet(); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ds.WriteXml("C:\text.xml");
Then On your crystal report Database Fields: change your dataset with "text.xml" If U have finish it, then create a dataset with your query, then change the code like this:
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet("YourDataSet"); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ReportDocument rd = new ReportDocument(); rd.SetDataSource = ds; crystalReportViewer1.ReportSource = rd;
Regard, Edwin
-
Hello Every body, I am new with crystal reports. I want to generate report for those employees whose age is more than 50 yrs. But I am not able to do so .It is showing all the records. I had added an crystal report in my project. I link it with the database through wizard only, On form1 it had inserted an crystal report viewer. on the load event of the form1 I had used the following code but it is use less. SqlConnection Connection = new SqlConnection("server='server1'; user id='sa'; password='admin'; database='employee'"); SqlCommand myCommand = new SqlCommand("SELECT * from companyEmp where age < '50'"); myCommand.Connection = Connection; myCommand.CommandType = CommandType.Text; SqlDataAdapter DA = new SqlDataAdapter(); DA.SelectCommand = myCommand; DataSet DS = new DataSet(); DA.Fill(DS); crystalReportViewer1.SetDataSource(DS.Tables[0]); crystalReportViewer1.ReportSource = objNewReport; But it is still showing all the record of companyEmp. Regards, rahul saini
Hi there . Look my friend you set you ReportViewer data source it's wrong . you must create new instance of your CrystalReport.rpt file . for example i have an report file named report.rpt . // Create new instance of your CrystalReport File Report _Report = new Report(); // Set Report data source ,no your viewer . _Report.SetDataSource(Your_DataSource); // Finally set your report viewer report source to your Report file . crystalReportViewer1.ReportSource = _Report;
DMASTER
-
Hi there . Look my friend you set you ReportViewer data source it's wrong . you must create new instance of your CrystalReport.rpt file . for example i have an report file named report.rpt . // Create new instance of your CrystalReport File Report _Report = new Report(); // Set Report data source ,no your viewer . _Report.SetDataSource(Your_DataSource); // Finally set your report viewer report source to your Report file . crystalReportViewer1.ReportSource = _Report;
DMASTER
Hi, I had use this also but again it is showing the same result.(all the records are showing) this the code i m using SqlConnection Connection = new SqlConnection("server='sName'; user id='sa'; password='admin'; database='employee'"); SqlDataAdapter DA = new SqlDataAdapter("SELECT empId,empName,empAge from companyEmp where age < 50", Connection); DataSet DS = new DataSet(); DA.Fill(DS); newReport objNewReport = new newReport(); objNewReport.SetDataSource(DS.Tables[0]); crystalReportViewer1.ReportSource = objNewReport ; Regards, rahul saini
-
Hello Edwin, When i m writing the xml it is giving me following error. ds.WriteXml("C:\text.xml"); Illegal characters in path. Regards, rahul saini
ds.WriteXml("C:\text.xml"); -- \t is the character code for a tab. You need to escape your backslashes by... using another backslash. ds.WriteXml("C:\\text.xml");
-
Hi, I had use this also but again it is showing the same result.(all the records are showing) this the code i m using SqlConnection Connection = new SqlConnection("server='sName'; user id='sa'; password='admin'; database='employee'"); SqlDataAdapter DA = new SqlDataAdapter("SELECT empId,empName,empAge from companyEmp where age < 50", Connection); DataSet DS = new DataSet(); DA.Fill(DS); newReport objNewReport = new newReport(); objNewReport.SetDataSource(DS.Tables[0]); crystalReportViewer1.ReportSource = objNewReport ; Regards, rahul saini
Wow , I got it .you are using untyped dataset , right ? look answer to my question I hope, I can help you . 1: Did you put any typed dataset in your report form ? 2: Did you used directly connection in report ? Send your email address to my mail : www.Developermaster61@gmail.com I hope, I elaborate in more detail .
DMASTER
-
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet(); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ds.WriteXml("C:\text.xml");
Then On your crystal report Database Fields: change your dataset with "text.xml" If U have finish it, then create a dataset with your query, then change the code like this:
SqlDataAdapter adapter = new SqlDataAdapter(yourQuery, conn); DataSet ds = new DataSet("YourDataSet"); DataTable dt = new DataTable("tablename"); adapter.Fill(dt); ds.Tables.Add(dt); ReportDocument rd = new ReportDocument(); rd.SetDataSource = ds; crystalReportViewer1.ReportSource = rd;
Regard, Edwin