Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Passing value from textbox to crystalreportviewer (parameterized query)

Passing value from textbox to crystalreportviewer (parameterized query)

Scheduled Pinned Locked Moved C#
databasehelptutorial
13 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N nt_virus

    Hello. I need a help . I m using CrystalReportViewer to display a table from dataset. I want to see specific details of particular id dynamically. Suppose the table is like this.. A -- B -- C A1 -- AAA -- BBB A2 -- BBB -- CCC ,, i can see full details in table but i want to see specific details like if a user enters A1 in textbox1, only A1 details will be shown.. I tried from past 2 days but i can't find a way... i was doing all things from interface, not by programming (by writing codes).. please tell me how to link that textbox with crystal report.. so i can see those data.. Thanks a lot...

    M Offline
    M Offline
    Member 4413283
    wrote on last edited by
    #2

    for this u can use crystalreport and file and add parameter field and create ParameterFields myParams = new ParameterFields(); ParameterField myParamGuestName = new ParameterField(); ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue(); myParamGuestName.ParameterFieldName = "guestname"; myParams.Add(myParamGuestName); crystalReportViewer.ParameterFieldInfo = myParams; enjoy this code diwaker sharma

    N 1 Reply Last reply
    0
    • M Member 4413283

      for this u can use crystalreport and file and add parameter field and create ParameterFields myParams = new ParameterFields(); ParameterField myParamGuestName = new ParameterField(); ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue(); myParamGuestName.ParameterFieldName = "guestname"; myParams.Add(myParamGuestName); crystalReportViewer.ParameterFieldInfo = myParams; enjoy this code diwaker sharma

      N Offline
      N Offline
      nt_virus
      wrote on last edited by
      #3

      sorry dude, i cant understand .. i have crystal report in my file ... where i write these code ? Do i need to fill dataset ? My existing code is like this ..

      private void button1_Click(object sender, EventArgs e)
      {
      sqlDataAdapter1.Fill(dataSet11);
      crystalReport11.SetDataSource(dataSet11);
      crystalReportViewer1.ReportSource = crystalReport11;

          }
      
      N T 2 Replies Last reply
      0
      • N nt_virus

        sorry dude, i cant understand .. i have crystal report in my file ... where i write these code ? Do i need to fill dataset ? My existing code is like this ..

        private void button1_Click(object sender, EventArgs e)
        {
        sqlDataAdapter1.Fill(dataSet11);
        crystalReport11.SetDataSource(dataSet11);
        crystalReportViewer1.ReportSource = crystalReport11;

            }
        
        N Offline
        N Offline
        nt_virus
        wrote on last edited by
        #4

        If you don't mind, can you please do the changes .. i will be very grateful to you ... http://www.mediafire.com/?sharekey=fe96050cdc6b5507d2db6fb9a8902bda[^] just few kbs.

        1 Reply Last reply
        0
        • N nt_virus

          sorry dude, i cant understand .. i have crystal report in my file ... where i write these code ? Do i need to fill dataset ? My existing code is like this ..

          private void button1_Click(object sender, EventArgs e)
          {
          sqlDataAdapter1.Fill(dataSet11);
          crystalReport11.SetDataSource(dataSet11);
          crystalReportViewer1.ReportSource = crystalReport11;

              }
          
          T Offline
          T Offline
          Tom Deketelaere
          wrote on last edited by
          #5

          First you need to add a parameter to your report. Then (still in the report) add a select query (from memory: right click report - set select - choice your ID column and set equal to parameter) Then in code you do: private void button1_Click(object sender, EventArgs e) { sqlDataAdapter1.Fill(dataSet11); crystalReport11.SetDataSource(dataSet11); crystalreport11.setparameter("parametername",value); crystalReportViewer1.ReportSource = crystalReport11; } This is all from memory so you might have to search a bit O and nobody is going to just write the code for you. But this should help you on your way.

          N 2 Replies Last reply
          0
          • T Tom Deketelaere

            First you need to add a parameter to your report. Then (still in the report) add a select query (from memory: right click report - set select - choice your ID column and set equal to parameter) Then in code you do: private void button1_Click(object sender, EventArgs e) { sqlDataAdapter1.Fill(dataSet11); crystalReport11.SetDataSource(dataSet11); crystalreport11.setparameter("parametername",value); crystalReportViewer1.ReportSource = crystalReport11; } This is all from memory so you might have to search a bit O and nobody is going to just write the code for you. But this should help you on your way.

            N Offline
            N Offline
            nt_virus
            wrote on last edited by
            #6

            System.Data.SqlClient.SqlException was unhandled
            Message="Parameterized Query '(@A varchar(50))SELECT DS.*\r\nFROM DS\r\nWHERE (A =' expects parameter @A, which was not supplied."
            Source=".Net SqlClient Data Provider"
            ErrorCode=-2146232060

            I get this error in this line ---- sqlDataAdapter1.Fill(dataSet11); What I did is ... Added a textbox1, button1, crystalreportviewer1 and crystalreport11, crystalreport.rpt.. in crystalreport.rpt, I added a Parameter Field , named "AAAA" and in Set Select Editor, I set equal to parameter and added A=@A in formula editor.. Then i write this code and error happens..

            sqlDataAdapter1.Fill(dataSet11);
                    crystalReport11.SetDataSource(dataSet11);
                    crystalReport11.SetParameterValue("AAAA", textBox1.Text);
                    crystalReportViewer1.ReportSource = crystalReport11;
            
            N T 2 Replies Last reply
            0
            • N nt_virus

              System.Data.SqlClient.SqlException was unhandled
              Message="Parameterized Query '(@A varchar(50))SELECT DS.*\r\nFROM DS\r\nWHERE (A =' expects parameter @A, which was not supplied."
              Source=".Net SqlClient Data Provider"
              ErrorCode=-2146232060

              I get this error in this line ---- sqlDataAdapter1.Fill(dataSet11); What I did is ... Added a textbox1, button1, crystalreportviewer1 and crystalreport11, crystalreport.rpt.. in crystalreport.rpt, I added a Parameter Field , named "AAAA" and in Set Select Editor, I set equal to parameter and added A=@A in formula editor.. Then i write this code and error happens..

              sqlDataAdapter1.Fill(dataSet11);
                      crystalReport11.SetDataSource(dataSet11);
                      crystalReport11.SetParameterValue("AAAA", textBox1.Text);
                      crystalReportViewer1.ReportSource = crystalReport11;
              
              N Offline
              N Offline
              nt_virus
              wrote on last edited by
              #7

              hey .. just worked tom .. thanks a lot my friend ... can i have your messenger id if you dont mind ...

              T 1 Reply Last reply
              0
              • N nt_virus

                System.Data.SqlClient.SqlException was unhandled
                Message="Parameterized Query '(@A varchar(50))SELECT DS.*\r\nFROM DS\r\nWHERE (A =' expects parameter @A, which was not supplied."
                Source=".Net SqlClient Data Provider"
                ErrorCode=-2146232060

                I get this error in this line ---- sqlDataAdapter1.Fill(dataSet11); What I did is ... Added a textbox1, button1, crystalreportviewer1 and crystalreport11, crystalreport.rpt.. in crystalreport.rpt, I added a Parameter Field , named "AAAA" and in Set Select Editor, I set equal to parameter and added A=@A in formula editor.. Then i write this code and error happens..

                sqlDataAdapter1.Fill(dataSet11);
                        crystalReport11.SetDataSource(dataSet11);
                        crystalReport11.SetParameterValue("AAAA", textBox1.Text);
                        crystalReportViewer1.ReportSource = crystalReport11;
                
                T Offline
                T Offline
                Tom Deketelaere
                wrote on last edited by
                #8

                It looks like you are trying to fill your dataset with an select query that requires an variable (@A) Wich is missing. (that is what the error says) first off all this isn't needed. You have 2 options: You select the complete table and do the filtering on the report (that is the way I explained it in earlyer post) OR You do the filtering in the select command and NOT on the report (in this case you don't need the parameter on the report) Both are possible and acceptable, you can do both but that's not needed. If you choice the second option you need to provide a sqlparameter something like:

                sqldataadapter1.selectcommand.commandtext = "SELECT * FROM table WHERE id=@A";
                sqldataadapter1.selectcommand.parameters.addwithvalue("@A",textbox1.text);
                sqldataadapter1.fill(dataset11);
                crystalReport11.SetDataSource(dataSet11);
                crystalReportViewer1.ReportSource = crystalReport11;

                and then your report doesn't need the parameter nor needs to filer it (the set select from last post) since you already filterd the data. (once again this if from memory)

                1 Reply Last reply
                0
                • N nt_virus

                  hey .. just worked tom .. thanks a lot my friend ... can i have your messenger id if you dont mind ...

                  T Offline
                  T Offline
                  Tom Deketelaere
                  wrote on last edited by
                  #9

                  nt_virus wrote:

                  can i have your messenger id if you dont mind ...

                  Messenger :confused: what's that :) I don't use it sorry, got bored off the viruses sending messages and the constant 20 boxes flashing :laugh:

                  1 Reply Last reply
                  0
                  • T Tom Deketelaere

                    First you need to add a parameter to your report. Then (still in the report) add a select query (from memory: right click report - set select - choice your ID column and set equal to parameter) Then in code you do: private void button1_Click(object sender, EventArgs e) { sqlDataAdapter1.Fill(dataSet11); crystalReport11.SetDataSource(dataSet11); crystalreport11.setparameter("parametername",value); crystalReportViewer1.ReportSource = crystalReport11; } This is all from memory so you might have to search a bit O and nobody is going to just write the code for you. But this should help you on your way.

                    N Offline
                    N Offline
                    nt_virus
                    wrote on last edited by
                    #10

                    Another problem, suppose there are two AgentID ... If i enters one agent Id and search for it , it works fine, but when i changes the value in textbox and enters 3nd agent id, it throws an error The SelectCommand property has not been initialized before calling 'Fill'. I have to search agentid and my search changes frequently .. so its not happing now.. Please suggest something.

                    T 1 Reply Last reply
                    0
                    • N nt_virus

                      Another problem, suppose there are two AgentID ... If i enters one agent Id and search for it , it works fine, but when i changes the value in textbox and enters 3nd agent id, it throws an error The SelectCommand property has not been initialized before calling 'Fill'. I have to search agentid and my search changes frequently .. so its not happing now.. Please suggest something.

                      T Offline
                      T Offline
                      Tom Deketelaere
                      wrote on last edited by
                      #11

                      Did you set the selectcommand? sorry without your code I can't really say what's wrong with it post your code that you use to fill the dataset

                      N 1 Reply Last reply
                      0
                      • T Tom Deketelaere

                        Did you set the selectcommand? sorry without your code I can't really say what's wrong with it post your code that you use to fill the dataset

                        N Offline
                        N Offline
                        nt_virus
                        wrote on last edited by
                        #12

                        Hello Sir, actually I use SqlDataAdapter and generate dataset not by coding .. should i do by coding ? I did everything from wizard ..

                        sqlDataAdapter1.Fill(dataSet11);
                        crystalReport11.SetDataSource(dataSet11);
                        crystalReport11.SetParameterValue("AAAA", textBox1.Text);
                        crystalReportViewer1.ReportSource = crystalReport11;

                        T 1 Reply Last reply
                        0
                        • N nt_virus

                          Hello Sir, actually I use SqlDataAdapter and generate dataset not by coding .. should i do by coding ? I did everything from wizard ..

                          sqlDataAdapter1.Fill(dataSet11);
                          crystalReport11.SetDataSource(dataSet11);
                          crystalReport11.SetParameterValue("AAAA", textBox1.Text);
                          crystalReportViewer1.ReportSource = crystalReport11;

                          T Offline
                          T Offline
                          Tom Deketelaere
                          wrote on last edited by
                          #13

                          Is this all your code? Where is your SQL string? The error message you get suggests that the selectcommand from your sqldataadapter isn't set wich from what I can see it isn't. to set the selectcommand: sqldataadapter.selectcommand.commandtext= "SELECT [insert your column names here] FROM [insert table name] WHERE [productid]= @id" sqldataadapter.selectcommand.parameters.addwithvalue("@id",textbox1.text) sqlDataAdapter1.Fill(dataSet11); crystalReport11.SetDataSource(dataSet11); crystalReportViewer1.ReportSource = crystalReport11;

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups