Shomen Deb

Shomen Deb

  • NA
  • 43
  • 0

crystal report parameterized views using C#.net

Nov 25 2008 4:05 AM
I want to create a crystal report which will be based on user input. User will give some inputs and on the basis of such input query will be performed and report will be displayed. I have created view like: CREATE VIEW first_view AS SELECT Book_id, ISBN_no, Tittle, Author, Publisher, Page, Country,user1 FROM book_information My coding is: string connstring = "Data Source=localhost; Initial Catalog=Book_Shop; Integrated Security=True"; SqlConnection conn = new SqlConnection(connstring); try { CrystalReport_First_User_Book objRpt = new CrystalReport_First_User_Book(); string selectstring = "select Book_id,ISBN_no,Tittle,Author,Publisher,Page,Country from first_view where user1=@user1"; SqlCommand comm = new SqlCommand(selectstring, conn); SqlDataAdapter adapter = new SqlDataAdapter(selectstring, conn); comm.Parameters.Add(new SqlParameter("@user1", userselect)); conn.Close(); conn.Open(); comm.ExecuteNonQuery(); DataSet ds = new DataSet(); adapter.Fill(ds, "first_view"); if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("No Data Found"); } objRpt.SetDataSource(ds); //CrystalDecisions.CrystalReports.Engine.TextObject root; //root = (CrystalDecisions.CrystalReports.Engine.TextObject) //objRpt.ReportDefinition.ReportObjects["txtHeader"]; //root.Text = "Sample Report With Parameter!!"; crystalReportViewer1.ReportSource = objRpt; } catch (SystemException exc) { MessageBox.Show(exc.Message); } finally { conn.Close(); } But message is displayed when I run the program like: "Must declare @user1" What should I do? Regards, Shomen

Answers (2)