I am trying to call selected records to my report but anytime I select with a predefined variable as my selection criteria a receive the entire table to the report but what I need are records who match my selection criteria.
Please take a look at my code.
Public Sub Today_Punches()
Dim Pass_Geter As New Pass_Geter
Dim tag As String
Dim Ds As New DataSet()
Dim tester As New streetDA
Dim Employee As String = "Emile Devere"
Dim Datum As String = "string"
Dim dateValue As Date
Dim Date_Day As String
Datum = "Mon, May 02, 16"
If Not IsPostBack Then
Dim dt As DataTable
Dim SQL As String = "SELECT Employee,Datum ,Punch_Type,Bracket FROM Today_punches where Today_punches.Datum = Datum"
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Using conn As New SqlConnection(strConnString)
Using comm As New SqlCommand(SQL, conn)
conn.Open()
Using da As New SqlDataAdapter(comm)
dt = New DataTable("tbl")
da.Fill(dt)
End Using
End Using
End Using
Dim _rdStudents As ReportDocument = New ReportDocument()
Dim reportPath As String = Server.MapPath("Company_Punches.rpt")
_rdStudents.Load(reportPath)
According to the posted code, I tested it in myside, I hope you could try the following steps to remove issue:
1. Add a breakpoint at the begin of this function, check if have triggered this method(Today_Punches).
2. About this parameter(Datum) in SqlCommand, I think it is not the valid parameter. Please try the following methods to add parameter value:
Sample Code:
Method1:
Dim SQL As String = "SELECT Employee,Datum ,Punch_Type,Bracket FROM Today_punches where Today_punches.Datum = " + Datum
Method2:
Using cmd As New MySqlCommand("SELECT Employee,Datum ,Punch_Type,Bracket FROM Today_punches where Today_punches.Datum =@Datum")
cmd.Parameters.AddWithValue("@Datum", Datum)
Best Regards,
Eric Du
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thanks for your answer, I think the first approach could be better suitable but by trying it I am getting an error message saying " Invalid Syntax near ' '.
According to this error message, I think this issue is caused by the SQL command, you need check if the fields exist in your database or your parameter value is a valid parameter.
Sample Code:
Dim parameter As Integer = Convert.ToInt32(TextBox1.Text)
Dim dt As New DataTable()
Dim SQL As String = "SELECT * FROM Movies where Movies.ID = " + parameter
Sample structure of the SQL:
Best Regards,
Eric Du
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
I am very glad to hear your problem has been solved. I hope you could mark your last replay as answer, this will better help someone who meet the same problem as you!
Best Regards,
Eric Du
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
43 Posts
Using Sql select with Crystal Report
Apr 07, 2017 01:44 PM|bonhommesanon|LINK
I am trying to call selected records to my report but anytime I select with a predefined variable as my selection criteria a receive the entire table to the report but what I need are records who match my selection criteria.
Please take a look at my code.
Public Sub Today_Punches()
Dim Pass_Geter As New Pass_Geter
Dim tag As String
Dim Ds As New DataSet()
Dim tester As New streetDA
Dim Employee As String = "Emile Devere"
Dim Datum As String = "string"
Dim dateValue As Date
Dim Date_Day As String
Datum = "Mon, May 02, 16"
If Not IsPostBack Then
Dim dt As DataTable
Dim SQL As String = "SELECT Employee,Datum ,Punch_Type,Bracket FROM Today_punches where Today_punches.Datum = Datum"
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Using conn As New SqlConnection(strConnString)
Using comm As New SqlCommand(SQL, conn)
conn.Open()
Using da As New SqlDataAdapter(comm)
dt = New DataTable("tbl")
da.Fill(dt)
End Using
End Using
End Using
Dim _rdStudents As ReportDocument = New ReportDocument()
Dim reportPath As String = Server.MapPath("Company_Punches.rpt")
_rdStudents.Load(reportPath)
_rdStudents.SetDataSource(dt)
CrystalReportViewer1.ReportSource = _rdStudents
End If
End Sub
Contributor
6680 Points
2715 Posts
Re: Using Sql select with Crystal Report
Apr 10, 2017 08:25 AM|Eric Du|LINK
Hi bonhommesanon,
According to the posted code, I tested it in myside, I hope you could try the following steps to remove issue:
1. Add a breakpoint at the begin of this function, check if have triggered this method(Today_Punches).
2. About this parameter(Datum) in SqlCommand, I think it is not the valid parameter. Please try the following methods to add parameter value:
Sample Code:
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
43 Posts
Re: Using Sql select with Crystal Report
Apr 10, 2017 02:35 PM|bonhommesanon|LINK
Hi Eric
Thanks for your answer, I think the first approach could be better suitable but by trying it I am getting an error message saying " Invalid Syntax near ' '.
Could you please let me know what that means
Contributor
6680 Points
2715 Posts
Re: Using Sql select with Crystal Report
Apr 11, 2017 02:30 AM|Eric Du|LINK
Hi bonhommesanon,
According to this error message, I think this issue is caused by the SQL command, you need check if the fields exist in your database or your parameter value is a valid parameter.
Sample Code:
Sample structure of the SQL:
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
43 Posts
Re: Using Sql select with Crystal Report
Apr 11, 2017 03:13 PM|bonhommesanon|LINK
Thanks Eric for your help. I got it to work by adding some extra. Take a look
Dim SQL As String = "SELECT Employee,Datum ,Punch_Type,Bracket FROM Today_punches where Today_punches.Datum ='" + Datum + "'"
Contributor
6680 Points
2715 Posts
Re: Using Sql select with Crystal Report
Apr 12, 2017 09:23 AM|Eric Du|LINK
Hi bonhommesanon,
I am very glad to hear your problem has been solved. I hope you could mark your last replay as answer, this will better help someone who meet the same problem as you!
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.