CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2002
    Location
    Newcastle, UK
    Posts
    23

    Crysal Reports Dynamic SQL

    Hi,
    I am trying to dynamically modify the columns that I display on a crystal report from VB.NET.

    I can easily modify the report parameters, the report selection criteria, but not the columns that i return from the database.

    Anybody have any suggestions??

    Thanks
    Steve

  2. #2
    Join Date
    Mar 2002
    Location
    Newcastle, UK
    Posts
    23
    I also want to be able to change by which column the report is sorted, and the sort direction (asc or desc)

    Basically, i want to be able to build the report either from a dataset, a recordset, or a SQL statement.

    Cheers.
    Steve

  3. #3
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    check out the example down below. Its reports are connected to created stored procedure, where you can modify the SQL statements as you like.

    Link

    /Leyan

  4. #4
    Join Date
    Mar 2002
    Location
    Newcastle, UK
    Posts
    23
    Leyan, Thanks.

    Unfortunately, I have this example already - it does not show how to customize the sql statement that the report uses - only how to modify the report design, and how to populate parameters that have already been created.

    I am wanting to modify the report SQL query so that I can alter the selected columns and the sorting characteristics.

    Any further suggestions would be appreciated.

    Steve

  5. #5
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    Maybe I'm not understanding your question fully, but.....

    In the "Windows Form Designer generated code" Region of that examples Main form, they create the stored procedures they link to the reports from an SQL statement, wich you can change. As I see it this is not necessary as you might create your own stored procedure to access.

    This is an example of what the do in that Region:
    Code:
    cmSQL.CommandText = "CREATE PROCEDURE dbo.GetAllCustomerOrders " & _
                            "AS " & _
                        "SELECT CUST.CompanyName, " & _
                            "ORD.OrderID, " & _
                            "ORD.OrderDate, " & _
                            "ORD.ShippedDate, " & _
                            "PROD.ProductName, " & _
                            "ORD_D.UnitPrice, " & _
                            "ORD_D.Quantity " & _
                        "FROM Customers CUST " & _
                            "INNER JOIN Orders ORD " & _
                            "ON CUST.CustomerID = ORD.CustomerID " & _
                            "INNER JOIN [Order Details] ORD_D " & _
                            "ON ORD.OrderID = ORD_D.OrderID " & _
                            "INNER JOIN Products PROD " & _
                            "ON ORD_D.ProductID = PROD.ProductID " & _
                            "ORDER BY ORD.OrderDate	" & _
                        "Return"
    /Leyan

  6. #6
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    As I changed the row....

    "ORDER BY ORD.OrderDate " & _

    to

    "ORDER BY ORD.OrderDate Desc" & _

    ....it changed the sort order of the reportto descending. Is not that what you wanted to do?

    /Leyan

  7. #7
    Join Date
    Mar 2002
    Location
    Newcastle, UK
    Posts
    23
    Athley,
    thanks again for your reply (I appreciate your persitance)

    The point you are missing (unless i am being very silly) and the problem I am having, is that I cannot change the columns displayed on a report.

    Even if I base the report on a view, then modify the view (for instance, add an extra column) I cannot change Crystal's SQL statement to display that extra column - likewise if I wish to hide a column from the report.


    Yes, you are right, I can base a report on a view, then change sort orders/selection criteria... but not the report columns!

    Any further ideas/help
    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured