Porting Crystal Report from VB6 to VB.NET - 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

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!

LINQ Crystal Reports

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/

VB.NET/Access DataGridView not displaying table contents

I'm attempting to display an Access Database table in a DataGridView on the most simple form you could make. However, when I start the application I don't see any of the table data. See below.
I'm happy to update with any additional information needed.
VB:
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MOKANDataSet.SalaryHistory' table. You can move, or remove it, as needed.
Me.SalaryHistoryTableAdapter.Fill(Me.MOKANDataSet.SalaryHistory)
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Here is the application at runtime.
Overview of project in Visual Studio
I was curious and went directly to the executable in the bin folder. Upon execution, I got "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. I'm using Win 7 64 Bit, but the Microsoft Office suite I have is 32-bit. I got the 32-bit AccessDatabase Engine referenced here

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

vb.net data not saved sql compact database when after closing the application

I did small application, to save insert data to table....
The application is not saving the data after the application close..
Can any one tell me what is the wrong in the code.
Imports System.Data
Imports System.Data.SqlServerCe
Public Class Form1
Public connstring As New String("Data Source=|DataDirectory|\test_db.sdf")
Public sqlconn As New SqlCeConnection(connstring)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim name As New String("jaifar")
Dim myCommand As New SqlCeCommand("Insert Into table1 (id) Values('" + name + "')", sqlconn)
If sqlconn.State = Data.ConnectionState.Closed Then sqlconn.Open()
myCommand.ExecuteNonQuery()
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
sqlconn.Close()
sqlconn = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Test_dbDataSet1.table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Test_dbDataSet1.table1)
End Sub
End Class
There are few ways to work around this:
If you select local database file in the Solution Explorer window, you will see a property called ‘Copy to Output’ in the Properties window. By default it is set to ‘Copy Always’ which means that on each build, the data files in the project folder will be copied to the output folder overwriting the existing data files if any. You can set this property to Copy Never and then manually put a copy of the data file in the output folder. This way, on subsequent builds, the project system will leave the datafile in the output folder and not try to overwrite it with the one from the project. The downside is that you still have two copies so after you modify the database file using the app, if you want to work on those changes in the project, you need to copy it to the project manually and vise-versa.
You can leave the data file outside the project and create a connection to it in Database Explorer. When the IDE asks you to bring the file into the project, just say no. This way, both the design-time and the run-time will be using the same data file but the downside is that the path in the connection string will be hard coded and therefore it’ll be harder to share the project and deploy the app. Before deploying the app, just make sure to replace the full path in the settings with a relative path.
Source: https://arnulfo.wordpress.com/2007/07/21/visual-studio-and-local-databases/
after
myCommand.ExecuteNonQuery()
then write
sqlconn.Close()
Cause, when you have write execute, better close it.
You must know that saving to dataset with database is not same.. Dataset is temporaly in your program, mean still not get change in database.
and, where is our + name + value??
Like,
mycommand.addwithvalue("name", the value place)