943,520 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1560
  • VB.NET RSS
Jun 17th, 2008
0

Syntax Error

Expand Post »
Ok, I had posted this-

http://www.daniweb.com/forums/thread128689.html

and got this piece of code from a link (http://vb.net-informations.com/cryst...ery_string.htm)


VB.NET Syntax (Toggle Plain Text)
  1.  
  2. Imports System.Data.SqlClient
  3. Imports CrystalDecisions.CrystalReports.Engine
  4. Imports CrystalDecisions.Shared
  5. Imports System.Data
  6. Public Class Form1
  7. Dim objRpt As New CrystalReport1
  8. Private Sub Button1_Click(ByVal sender As System.Object,
  9. ByVal e As System.EventArgs) Handles Button1.Click
  10. Dim cnn As SqlConnection
  11. Dim connectionString As String
  12. Dim sql As String
  13.  
  14. connectionString = "data source=SERVERNAME; _
  15. initial catalog=crystaldb;user id=sa;password=PASSWORD;"
  16. cnn = New SqlConnection(connectionString)
  17. cnn.Open()
  18. sql = procesSQL()
  19. Dim dscmd As New SqlDataAdapter(sql, cnn)
  20. Dim ds As New DataSet1
  21. dscmd.Fill(ds, "Product")
  22. objRpt.SetDataSource(ds.Tables(1))
  23. CrystalReportViewer1.ReportSource = objRpt
  24. CrystalReportViewer1.Refresh()
  25. End Sub
  26. Public Function procesSQL() As String
  27. Dim sql As String
  28. Dim inSql As String
  29. Dim firstPart As String
  30. Dim lastPart As String
  31. Dim selectStart As Integer
  32. Dim fromStart As Integer
  33. Dim fields As String()
  34. Dim i As Integer
  35. Dim MyText As TextObject
  36.  
  37. inSql = TextBox1.Text
  38. inSql = inSql.ToUpper
  39.  
  40. selectStart = inSql.IndexOf("SELECT")
  41. fromStart = inSql.IndexOf("FROM")
  42. selectStart = selectStart + 6
  43. firstPart = inSql.Substring(selectStart, (fromStart - selectStart))
  44. lastPart = inSql.Substring(fromStart, inSql.Length - fromStart)
  45.  
  46. fields = firstPart.Split(",")
  47. firstPart = ""
  48. For i = 0 To fields.Length - 1
  49. If i > 0 Then
  50. firstPart = firstPart & " , " _
  51. & fields(i).ToString() & " AS COLUMN" & i + 1
  52. MyText = CType(objRpt.ReportDefinition.ReportObjects("Text" _
  53. & i + 1), TextObject)
  54. MyText.Text = fields(i).ToString()
  55. Else
  56. firstPart = firstPart & fields(i).ToString() & _
  57. " AS COLUMN" & i + 1
  58. MyText = CType(objRpt.ReportDefinition.ReportObjects("Text" & _
  59. i + 1), TextObject)
  60. MyText.Text = fields(i).ToString()
  61. End If
  62. Next
  63. sql = "SELECT " & firstPart & " " & lastPart
  64. Return sql
  65. End Function
  66.  
  67. End Class


The error is reported on the line-

Dim objRpt As New CrystalReport1


What should have been the correct Syntax? Or does it require me to have an API to handle Crystal Reports (if it does not come native with VS 2008 Pro)
Similar Threads
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jun 18th, 2008
0

Re: Syntax Error

Maybe it is because there is no report (=class) "CrystalReport1" in your project.
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 18th, 2008
0

Re: Syntax Error

Does Importing some API make the CrystalReport class available?
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jun 18th, 2008
2

Re: Syntax Error

Sorry, I do not understand what you mean with "Importing some API"

The RT must be able to instantiate a class named "CrystalReport1", else the line
Dim objRpt As New CrystalReport1 cannot work.

Normally you would create such a class by adding a crystal report named "CrystalReport1.rpt" into your project. For VS 2003:
  • Rightclick the project in the solution explorer
  • Select "Add New Item"
  • Select "Crystal Report" in the "Add New Item" Dialog, give it the name "CrystalReport1.rpt", finish with "Open".
  • Follow the instructions in the Crystal Report "Wizzard" Gallery.
After this there is a report (=class) CrystalReport1 in your project that can be instantiated.
Reputation Points: 25
Solved Threads: 5
Newbie Poster
dadelsen is offline Offline
22 posts
since Jun 2007
Jun 18th, 2008
0

Re: Syntax Error

I did as you said and its working now.

Thankie!
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Search for files within certain date range
Next Thread in VB.NET Forum Timeline: prompting when chnages have been made to a text box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC