Shomen Deb

Shomen Deb

  • NA
  • 43
  • 0

how to pass sql query parameter to crystal report using C#.net

Nov 29 2008 4:28 AM
I have read the article http://www.c-sharpcorner.com/UploadFile/rehan2004/Crystal_Reportwith_net08052008041806AM/Crystal_Reportwith_net.aspx. My view is like that: CREATE VIEW dbo.pub_sold_view AS SELECT * FROM dbo.book_information a INNER JOIN dbo.Invoice_single b ON a.Book_id = b.Book_id And In my code, I've written like this: Pub_Book_Sold_Report objRpt = new Pub_Book_Sold_Report(); string selectstring = "select Book_id,Tittle,Author,Publisher,Country,user1 from pub_sold_view where Publisher=@Publisher"; SqlCommand comm = new SqlCommand(selectstring, conn); SqlDataAdapter adapter = new SqlDataAdapter(selectstring, connstring); comm.Parameters.AddWithValue("@Publisher",publisherstr); DataSet ds = new DataSet(); adapter.Fill(ds, "pub_sold_view"); DataTable dt = ds.Tables["pub_sold_view"]; if (dt.Rows.Count == 0)//ds.Tables[0].Rows.Count == 0) { MessageBox.Show("No Data Found"); } objRpt.SetDataSource(dt);//ds); crystalReportViewer1.ReportSource = objRpt; But it is not working. Message is given like "Must declare @Publisher" I've tried with string selectstring = "select Book_id,Tittle,Author,Publisher,Country,user1 from pub_sold_view where Publisher=" + Publisher; But it's also not working. Message is given like "Invalid column name 'xyz'" How can I set parameter for views to pass that parameter to crystal report? or Is there any other way?? Regards, Shomen

Answers (8)