LINQ Crystal Reports - vb.net

i am using visual studio 2010 to write a program which uses crystal report. when i supply my linq query result as data source for my crystal report i receive the error : "The report has no tables"
This is my code written in vb.net
Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.Common
Imports System.Data.Objects
Imports System.Data.Objects.DataClasses
Public Class Form1
Dim rpt As New CrystalReport1
Dim context As New InvoiceSystemEntities
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim c = From cust In context.Customers
Select cust
rpt.SetDataSource(c)
CrystalReportViewer1.ReportSource = rpt
End Sub
End Class
My main reason for my concern is that i want to gain control of the query i send to crystal reports so that i set parameters inside the queries rather than use crystal report to set the parameters. Can anyone please help me out?

You cannot mix and match the datasource in crystal reports. You should use the same datasource which you have used while designing the report.
To use entity as datasource Go to field explorer -> Database fields -> Project Data-> .NET objects . You should see "InvoiceSystemEntities' listed there. Just select and use it your report. Rest of the code should work without any issue
you can see it how it is done from this tutorial
http://tektutorialshub.com/create-crystal-reports-in-asp-net-mvc/

Related

VB.Net 2013 How do I programatically update a bindingsource without getting late binding errors/warnings?

I created a DataSet with a DataTable & TableAdapter that contains Select/Update/Insert/Delete commands that relate to my MSSQL database. The DataTable selects all the fields from a Person table (two fields in particular a LastName string and an UpdateUserID int).
Then I made a simple test form with a textbox and a button. From the Data Sources tab, I dragged the LastName field onto the form. This creates MyDataset, MyTableAdapter, and MyBindingSource on the form. It also databinds the textbox to the LastName field of the BindingSource.
Here's the complete code for the form:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
loadData()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Validate()
Me.MyBindingSource.EndEdit()
' Me.MyBindingSource.Current("updateUserID") = 123
Me.MyTableAdapter.Update(Me.MyDataset.myDatatable)
loadData()
End Sub
Private Sub loadData()
Me.MyTableAdapter.Fill(Me.MyDataset.myDatatable)
End Sub
End Class
This all works completely fine. The problem occurs when I uncomment the line: "Me.MyBindingSource.Current("updateID") = 123". I'm trying to set the UpdateID to save the ID of the user that most recently made a change.
In Visual Studio 2008, this worked fine. But I just upgraded to 2013 and now I'm getting an error that says "Option Strict On disallows late binding."
(PS, this is a test program. In the actual program - converted from 2008 - I only get warnings saying "Late bound resolution; runtime errors could occur.")
I understand why I'm getting these errors/warnings: because the IDE doesn't know what DataType the "updateUserID" DataColumn is.
But what can I do to manually update the BindingSource before saving? I don't think turning Option Strict off is a good idea.
The DataColumns in the DataTable have their DataTypes specified. Is there a way to reference the DataColumn directly instead of through the string of its name?
I'm looking for something like:
Me.MyBindingSource.Current.DataColumns.UpdateUserID.value = 123
Thanks for any help!

creating text file in wp7 using vb.net

I have tried following code:
imports system.io
imports system.io.isolatedstorage
private sub Button_Click(sender as system.object, e as system.windows.routedeventargs) handles button1.click
dim isoStore As IsolatedStorageFile = isolatedstoragefile.getuserstoreforapplication
isostore.createfile("c:\test.txt")
end sub
when i run the code on windows phone emulator it shows exception "Operation not permitted on isolatedstoragefilestream"
Windows Phone is not like a PC operating system, there is no C:\ - each app has it's own contained area where you store and access files, hence the name IsolatedStorage.
GeekChamp has a great tutorial on IsolatedStorage, which is in C#.
For VB.Net, the following code sample should help you getting started with IsolatedStorage:
http://code.msdn.microsoft.com/wpapps/VBWP8ImageFromIsolatedStora-11071695

Porting Crystal Report from VB6 to VB.NET

I have done a tonne of work in porting quite a large VB6 project over to .NET but have hit a snag on the crystal reports. I've converted the dsr files to rpt. The next stage is getting it into the code
The VB6 way was to use the following
Dim report As New cryMyReport
Even after importing the rpt files into the project, cryMyReport is not recognised.
What do I need to do to get my .NET app recognise and use the rpt files?
I often refer people to http://vb.net-informations.com/crystal-report/vb.net_crystal_report_step_by_step.htm
Essentially you need to add the Crystal references (you will need the Crystal reports for visual studio runtimes installed), add a CrystalReportViewer and then use some code along the lines of:
Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class

how to connect SQL and R.Net?

I want to connect SQL database from R.Net. I am using R.Net from vb.net.
Is it possible? If it possible how?
Using vb.net i have added some .DLL file (R.Net.dll,RdotNET.dll) which will help to work R.Net and i did some coding to find sum.
code:
Imports RdotNET
Public Class Form1
Dim engine As REngine
Dim sum As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
REngine.SetDllDirectory("#C:\Program Files\R\R-2.12.0\bin\i386")
engine = REngine.CreateInstance("RDotNet")
engine.EagerEvaluate("sum<- 5 + 6")
sum = engine.GetSymbol("sum").AsNumeric.First()
MessageBox.Show(sum.ToString)
End Sub
now i need to connect to Sql. i need to read a table data and display it in a my app
sorry for my bad English.
Writing R code that uses R.NET to call a .NET connection to a SQL database seems like an overcomplicated way of doing things. Unless your use case demands this (edit your question to explain what you are doing), I recommend using one of the many R packages that connect directly to SQL databases. Take a look at dbConnect, RMySQL, RPostgreSQL, RODBC, RSQLite or RpgSQL, depending upon what sort of database it is.

Crystal Reports: Is there a way to get effectively a subreport within a subreport?

UPDATE: I asked a more general question here: Can I do two levels of linking in Crystal Reports?
I'm using Crystal Reports within VB.NET and Visual Studio 2005.
I have a report with several subreports. I'm setting List(Of MainStuff) as the data sources for the main report. I'm setting List(Of SubreportStuff) as the data source for the subreport. Each SubreportStuff has a key which links back to a particular MainStuff, so the report groups each MainStuff item with its related SubreportStuff items. (Or, at the DB level, SubreportStuff items have a foreign key, which is the primary key in MainStuff.)
Below shows the Load function for the dialog, which contains a CrystalReportsViewer. In the Crystal Reports report editor (within VS 2005) I set the subreport link to pull only the related items into that part of the report.
Imports System.Windows.Forms
Public Class dlgMyReport
Private rpt As New MyReport
Public theMainList As New List(Of MainStuff)
Dim theSubreportList As New List(Of SubreportStuff)
Private Sub dlgMyReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rpt.SetDataSource(theMainList)
If theSubreportStuff.Count > 0 Then
rpt.Subreports.Item("subReport").SetDataSource(theSubreportList)
End If
Me.StuffViewer.ReportSource = rpt
End Sub
... ' other subs and functions
End Class
This works fine.
Now, though, what I'm needing to do is in essence the same thing, but pull items based on the keys in the subreport items. This would mean having a subreport within a subreport. However, it doesn't appear that I can do this (the option for inserting a subreport is grayed out when I try to insert in something that is already a subreport).
Is there a way that I can accomplish this? (Can I carry the subreport relationship down another level in some way?)
Thanks as always!
Subreports within subreports are not possible within Crystal Reports.