|
It's 2016 and it still works like a charm!
Thank you very much!
Using visual studio 2015 with .NET Framework 4.0 and the latest Crystal Report available.
To make it to work I had to add a value to my app.config, to solve the error
Could not load file or assembly ‘[...]\crdb_adoplus.dll’ or one of its dependencies.
So, my app.config is now
="1.0"="utf-8"
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
|
|
|
|
|
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath.ToString() + @"\test.mdb" + ";Persist Security Info=True";
OleDbConnection empConnection_FCT = new OleDbConnection(connstr);
empConnection_FCT.Open();
CrystalReport1 objRpt = new CrystalReport1();
string getRptData =("SELECT * FROM TABLE" );
datAdptr = new OleDbDataAdapter(getRptData, empConnection_FCT);
ds = new DataSet();
datAdptr.Fill(ds);
try
{
objRpt.DataSourceConnections[0].SetConnection("", Application.StartupPath.ToString() + @"\test.mdb", true);
// Set Username and Password.
objRpt.DataSourceConnections[0].SetLogon("", ""); // if your mdb is pasword protected DataSourceConnections[0].SetLogon("username", "password");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
objRpt.SetDataSource(ds);
CrystalDecisions.CrystalReports.Engine.TextObject root;
root = (CrystalDecisions.CrystalReports.Engine.TextObject)objRpt.ReportDefinition.ReportObjects[0];
root.Text = "Report on IV Module!!";
// Binding the crystalReportViewer with our report object.
crystalReportViewer1.ReportSource = objRpt;
empConnection_FCT.Close();
Harshal Doshi,
Embedded Systems,
Firmware Design,
Software Solutions.
|
|
|
|
|
hi Imran A Momin
You did a great job...
i'm alos faced the same problem for last two weeks...
but i just did it in another way...
i replaced ur try block with the below and its works fine...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rpt As New CrystDem
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Application.Info.DirectoryPath & "/HSS.mdb")
'"SELECT `tblCurGust`.`cg_RoomNum`, `tblCurGust`.`cg_GuestID`, `tblCurGust`.`cg_GuestName`, `tblCurGust`.`cg_NoofGusts`, `tblCurGust`.`cg_ArriDate`, `tblCurGust`.`cg_DaysBooking`, `tblCurGust`.`cg_AdvPaid`, `tblCurGust`.`cg_Balance` FROM `tblCurGust` `tblCurGust`"
Dim cmd As New OleDbCommand("SELECT `tblCurGust`.`cg_RoomNum`, `tblCurGust`.`cg_GuestID`, `tblCurGust`.`cg_GuestName`, `tblCurGust`.`cg_NoofGusts`, `tblCurGust`.`cg_ArriDate`, `tblCurGust`.`cg_DaysBooking`, `tblCurGust`.`cg_AdvPaid`, `tblCurGust`.`cg_Balance` FROM `tblCurGust` `tblCurGust`")
cmd.CommandType = CommandType.Text
cmd.Connection = con
Dim da As New OleDbDataAdapter
da.SelectCommand = cmd
Dim ds As New DataSet
da.Fill(ds, "tblCurGust")
Try
rpt.Database.Tables("tblCurGust").SetDataSource(ds)
'rpt.DataSourceConnections.Item(0).SetConnection("", "" & My.Application.Info.DirectoryPath & "\HSS.md", False)
'rpt.DataSourceConnections.Item(0).SetLogon("Admin", "")
Catch ex As Exception
MsgBox(ex.Message)
End Try
rptvwer.ReportSource = rpt
rptvwer.Refresh()
End Sub
|
|
|
|
|
Not workin for me, bellow is the code the changes i made, in crystal report i am using OLEDB(ADO) Microsoft.Jet.OLEDB.4.0 MS Access .mdb, there is no password..
http://img43.imageshack.us/img43/75/40042195.png
it works on the system but when i transfer it to a new system, it checks the wrong database location,(the DB location in my PC) ..
Imports System.Data.OleDb
Public Class aging_report
Dim rpt1 As New CrystalReport6
Dim path1 As String = My.Application.Info.DirectoryPath '' path
Private Sub aging_report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=|DataDirectory|\MOMDB.mdb;" & _
"Persist Security Info=True;" & _
"Jet OLEDB:Database Password=")
Dim com As New OleDbCommand("SELECT `unpaid_trans`.`PatTranCode`, `unpaid_trans`.`PatCode`, `unpaid_trans`.`PatSurname`, `unpaid_trans`.`Total`, `unpaid_trans`.`TranDate` " & _
"FROM `unpaid_trans` `unpaid_trans`")
com.CommandType = CommandType.Text '' command type
com.Connection = con '' give connection to command
Dim adp As New OleDbDataAdapter '' declare adapter
adp.SelectCommand = com '' select command for adpapter to work on
Dim ds As New DataSet '' delcare dataset
adp.Fill(ds, "Crystal") '' fill the dataset through adapter
Try
rpt1.DataSourceConnections.Item(0).SetConnection("", "" & path1 & "\MOMDB.mdb", False)
rpt1.DataSourceConnections.Item(0).SetLogon("Admin", "")
Catch exp As Exception
MsgBox(exp.Message)
End Try
rpt1.SetDataSource(ds) '' select the Dataset to the source of the report
CrystalReportViewer1.ReportSource = rpt1 '' assign the report to the crytal reprot viewr (cr1)
modified on Friday, January 14, 2011 11:47 PM
|
|
|
|
|
Hello,
You have a wrong connection String. If you dont have password then dont use the attribute of password " Jet OLEDB:Database Password=admin "
for more help on connection string check this website http://www.connectionstrings.com/[^]
Imran A Momin
Co.Software Developer
|
|
|
|
|
I changed, still on other system, the report looks the wrong data-source location .
Imports System.Data.OleDb
Public Class aging_report
Dim rpt1 As New CrystalReport6
Dim path1 As String = My.Application.Info.DirectoryPath '' path
Private Sub aging_report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=|DataDirectory|\MOMDB.mdb;" & _
"Persist Security Info=False;")
Dim com As New OleDbCommand("SELECT `unpaid_trans`.`PatTranCode`, `unpaid_trans`.`PatCode`, `unpaid_trans`.`PatSurname`, `unpaid_trans`.`Total`, `unpaid_trans`.`TranDate` " & _
"FROM `unpaid_trans` `unpaid_trans`")
com.CommandType = CommandType.Text '' command type
com.Connection = con '' give connection to command
Dim adp As New OleDbDataAdapter '' declare adapter
adp.SelectCommand = com '' select command for adpapter to work on
Dim ds As New DataSet '' delcare dataset
adp.Fill(ds, "Crystal") '' fill the dataset through adapter
Try
rpt1.DataSourceConnections.Item(0).SetConnection("", "" & path1 & "\MOMDB.mdb", False)
rpt1.DataSourceConnections.Item(0).SetLogon("", "")
Catch exp As Exception
MsgBox(exp.Message)
End Try
rpt1.SetDataSource(ds) '' select the Dataset to the source of the report
CrystalReportViewer1.ReportSource = rpt1 '' assign the report to the crytal reprot viewr (cr1)
End Sub
|
|
|
|
|
then set logon method rpt1.DataSourceConnections.Item(0).SetLogon("", "") is incorrect.
u need to add the username to the method
Imran A Momin
Co.Software Developer
|
|
|
|
|
i tried with Admin as the username, since that is the default one, no luck thats why i removed it, just checked again, no good.. any ideas..
rpt1.DataSourceConnections.Item(0).SetLogon("Admin", "")
|
|
|
|
|
|
hey man, it's really helped me....
keep it up
Thanks & Regards
S. Sivakumar
|
|
|
|
|
Hello, I've followed your code but at the end the server still ask me the password, could you tell me why.
My code is:
private void Form1_Load(object sender, EventArgs e)
{
CrystalReport2 rpt = new CrystalReport2();
string connectionstring = GetConnectionString();
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand comm = new SqlCommand(GetQuery());
comm.CommandType = CommandType.Text;
comm.Connection = con;
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = comm;
DataSet ds = new DataSet();
adp.Fill(ds, "Crystal");
try
{
rpt.DataSourceConnections[0].SetConnection("Localhost", "Test", false);
rpt.DataSourceConnections[0].SetLogon("testUser", "testUser");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
rpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rpt;
}
static private string GetConnectionString()
{
return "Data Source=Localhost; Initial Catalog= Test; User Id=testUser; Password=testUser;";
}
static private string GetQuery()
{
return "SELECT AnFacAbCom.[Document No_], " +
"AnFacAbCom.Name, " +
"AnFacAbCom.Type, " +
"AnFacAbCom.Description " +
"FROM Analitica_Fact_Abonos_Compra as AnFacAbCom" ;
}
Before the report will be showed, the server connection window appear.
Hope you can help me!
Regards
|
|
|
|
|
I tried ur code. and found out that the SQL Server does not allow to do so. Instead i had to use the DNS datasource for this.
Sorry i couldn't help you out.
If any time i get the solution i will do reply you back.
Thank you
Imran A Momin
Co.Software Developer
|
|
|
|
|
|
I been looking for this for long time
Worked for me!
Great
|
|
|
|
|
Thanx a lot. I used the same with Visual Studio 2008.
Deepak Shah
Infinite Software Solutions
www.infinitess.com
|
|
|
|
|
I am working on Asp.net 2008 window project. When I design Crystal Report I am using DB from my bin\debug\ folder. I am using Access Function to design report.During Project deployment I am design Setup project and also add report file and DB file in Setup.
Using Application.StarupPath I can create my connection string and retrive dataset. Set this dataset as my report dataset.
Now problem is at runtime DB is differ then as design time so I get Err.
I am getting err while DB verification at report using verifyDataBase() function. If I am not use this function then report use my local DB address to design Report at Client End.
|
|
|
|
|
I got it .. I use to face the same kind of problem.. when i use to call the verifydatabase() method
Now this method check if any changes are made to the database, if any it does the changes to the report else well means .. it will most propably will delete the field or table if they dont exits.
So what i did is that .. tried to kept the same fields and tables that i used to design the reports.. so i wont get any errors ... and i was succesfull in that..
Hope u get the answer u need..
Imran A Momin
Co.Software Developer
|
|
|
|
|
i am using Crystal Reports XI R2 and Visual Basic 2005, i'm having problem previewing the report after binding the ReportDocument.SetDatasource to a DataSet, but if i print directly or export there is no problem.
this is my code.
Dim SQL As String<br />
Dim CRXiReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument<br />
Try<br />
<br />
SQL = "SELECT WFLotNo, ChipModelName, WFQty, Location, StockInDate, StockInUser FROM StockReport2"<br />
RptSource(SQL, "StockReport")'Subroutine to populate the RptDataset<br />
With CRXiReport<br />
.Load(Application.StartupPath & "\Reports\StockReport.rpt", OpenReportMethod.OpenReportByDefault)<br />
.SetDataSource(RptDataSet.Tables("StockReport"))<br />
.VerifyDatabase()<br />
'.PrintToPrinter(1, False, 1, 1) 'This works fine<br />
End With<br />
<br />
'Stock Report<br />
FrmViewer = Nothing<br />
FrmViewer = New FrmCRXi<br />
With FrmViewer<br />
.CrystalReportViewer1.ReportSource = CRXiReport<br />
.Show() 'Shows only the ReportViewer without any report!<br />
End With<br />
<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try
Here's the Screenshot http://www.flickr.com/photos/16102763@N05/1912653386/
-- modified at 22:53 Wednesday 7th November, 2007
|
|
|
|
|
Sir I am having difficulty with this example, which I am sure is due to my being new to VB.
I am using VisualStudio 2005.
My goal is to create a standard CrystalReport, and allow the user to select the DB file to use, using an openfiledialog box.
When i create the report, it asks for the DB file to use. ( I assume this would be default DB) - I select the DB, & design a simple test report.
I cannot get this to compile, because I get the error: Error 1 Property 'ReportSource' is 'ReadOnly'
at the line: cr.ReportSource = rpt '' assign the report to the crytal reprot viewr (cr)
What am I doing wrong ? Thanks for any help you can give me.
Here is the code:
<br />
Imports System.Data.OleDb<br />
<br />
Public Class Form1<br />
Dim rpt As New CrystalReport1<br />
'Dim rpt1 As New CrystalReport2<br />
<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim path1 As String = My.Application.Info.DirectoryPath '' path<br />
<br />
OpenFileDialog1.Filter = "MS Access Files (*.mdb) | *.mdb"<br />
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then<br />
End If<br />
<br />
Try<br />
rpt.DataSourceConnections.Item(0).SetConnection("", "" & OpenFileDialog1.FileName & "", False)<br />
<br />
<br />
'rpt.DataSourceConnections.Item(0).SetConnection("", "" & path1 & "\Xtreme.mdb", False)<br />
<br />
'' if password is given then give the password<br />
<br />
'' if not give it will ask at runtime<br />
<br />
rpt.DataSourceConnections.Item(0).SetLogon("admin", "admin")<br />
<br />
cr.ReportSource = rpt '' assign the report to the crytal reprot viewr (cr)<br />
Catch ex As Exception<br />
<br />
MsgBox(ex.Message)<br />
End Try<br />
<br />
<br />
End Sub<br />
<br />
<br />
End Class<br />
<br />
|
|
|
|
|
Hello I think the Problem lies in
OpenFileDialog1.Filter = "MS Access Files (*.mdb) | *.mdb"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
End If
Try
rpt.DataSourceConnections.Item(0).SetConnection("", "" & OpenFileDialog1.FileName & "", False)
Where the rpt.datasource, u have given only the filename and not the filepath, coz that could be the reason for the error u recive..
Another thing is ,, whether the Crystalreport1 file is ReadOnly. If it is,, do check it..
Imran
|
|
|
|
|
Hi, Thank you very much for your code.
The question is can I use Record Set? Can you show me how?
For example:
rsCliList = New ADODB.Recordset
With rsCliList
.Fields.Append("ID", ADODB.DataTypeEnum.adBSTR)
. ....
.Open()
End With
Dim nn As Integer
rs.Open("Select * from Client", conn1,_
ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
Do Until rs.EOF
rsCliList.AddNew()
rsCliList.Fields("ID").Value = rs.Fields("Cl_ID").Value
Exit Do
rs.MoveNext()
Loop
rs.Close()
rpt1.SetDataSource(rsCliList)
crViewer1.ReportSource = rpt1
|
|
|
|
|
Thank you. It was helpfull! I gave you 5.
|
|
|
|
|
Thanx for your support...
|
|
|
|
|
hi,
i set dynemically change access database of crystal reports with vb.net.
i have not given any password to database.
i have problem for at,
rpt.DataSourceConnections.Item(0).SetLogon("admin", "admin)
at runtime i have problem for password, i give user="Admin" and password "" or user="admin" and password "admin".
it not accept any password and user.
rgds,
irfan
-- modified at 7:08 Thursday 29th March, 2007
-- modified at 7:11 Thursday 29th March, 2007
irfan pathan
|
|
|
|
|
U could try this out... Coz i am using it...
rpt.Datasourceconnections.item(0).setlogon("Admin","")
I guess it should work...
Hope u found it usefull
|
|
|
|
|