Syntax Error

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Syntax Error

 
0
  #1
Jun 17th, 2008
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)


  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)
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Syntax Error

 
0
  #2
Jun 18th, 2008
Maybe it is because there is no report (=class) "CrystalReport1" in your project.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Syntax Error

 
0
  #3
Jun 18th, 2008
Does Importing some API make the CrystalReport class available?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 22
Reputation: dadelsen is an unknown quantity at this point 
Solved Threads: 5
dadelsen dadelsen is offline Offline
Newbie Poster

Re: Syntax Error

 
2
  #4
Jun 18th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Syntax Error

 
0
  #5
Jun 18th, 2008
I did as you said and its working now.

Thankie!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1152 | Replies: 4
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC