PDA

View Full Version : چگونه مسیر داینامیک به بانک اکسس را به کریستال ریپورت بدهم



H_Ghaffarian
چهارشنبه 25 خرداد 1384, 17:22 عصر
سلام
من با vb.net و بانک access و crystal report فرمی را طراحی کرده ام. اما به هیچ طریقی امکان آن را نیافتم که مسیر جدول را در برنامه و برای زمان اجرا به ریپورت بدهم. موارد موجود در این بخش و بسیاری سایتهای دیگر نیز برای کار با vb 6.0 بود. من کد زیر را در پروژه بکار بردم اما هنوز هم مسیر فایل اکسس در زمان اجرا از من خواسته می شود:

Dim Report = New Chart1
Dim dtAd As New OleDbDataAdapter
dtAd = New OleDbDataAdapter("SELECT * FROM tbChart;", con)
dtAd.Fill(DS, "tbChart")
Report.SetDataSource(DS)
CRV.ReportSource = Report

لطفاً در صورت امکان نحوه اعمال تغییر مسیر جدول را با ذکر مثال تشریح کنید. البته من حتی مسیر فایل را نیز به کمک دستور application.startpath نیز به Crystal report بصورت زیر دادم که بازهم جواب نداد:

CRV.ReportSource = Application.StartupPath + "\" + "Chart.rpt"
Please help me :(

In_Chan_Nafar
جمعه 27 خرداد 1384, 02:29 صبح
این سورس واسه SQL Server هست اگه یه کمی دست کاری کنی کارت را می یوفته


Dim rpt As New CrystalReport1() 'The report you created.
Dim myConnection As SqlConnection
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New Dataset1() 'The DataSet you created.

Try

myConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=northwind;")
MyCommand.Connection = myConnection
MyCommand.CommandText = "SELECT * FROM Customers"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand

myDA.Fill(myDS, "Customers")
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt

Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

H_Ghaffarian
شنبه 28 خرداد 1384, 09:23 صبح
سلام
دوستان عزیز اگه یکمی دقت می کردید می دیدید که کدی که برای من نوشتید دقیقاً همون کد خودمه که فقط چند تا اسم توی اون عوض شده. Chart1 در حقیقت همون Report طراحی شده منه و CRV هم همون CrystalReportViewer منه. Report هم همون rpt تعریف شده شماست.اما همونطور که گفتم این کد جواب نمی ده و در حین اجرای برنامه در پنچره ای که توسط خود Crystal Report باز می شه مسیر بانک رو از من می خواد و این اتفاق در هر بار اجرای برنامه از ابتدا , تکرار می شه که آزار دهنده است.
Please Help me :cry:

In_Chan_Nafar
شنبه 28 خرداد 1384, 22:30 عصر
سلام

شما اگه کمی با دقت جستجو می کردی می تونستی تو همین بخش جوابتون رو دریافت کنید

حالا من لینکش واستون می ذارم (ولی از الان بگم که این کد واسه سی شارپ هست ولی خیلی ساده می تونید اون رو به VB تبدیل کنید) :mrgreen:

http://www.barnamenevis.org/forum/viewtopic.php?t=22190[url]
:موفق:

H_Ghaffarian
یک شنبه 29 خرداد 1384, 09:45 صبح
سلام
اول بابت راهنمایی و لینک مزبور ممنون. قبلاً اون رو دیدم. :sorry:
::نوشتن:: دوم اینکه من قبلاً هم گفتم که بانک من اکسس و نه sql server است. در ارتباط با sql server هیچ موقع از مسیر فیزیکی بانک سئوال نمی شه و این وظیفه خود سرور sql می باشد. تنها نام سرور مسئله اصلی کاره که مشکل خاصی نداره. اما در مورد اکسس باید مسیر فیزیکی بانک اطلاعاتی داده بشه و بدون اون کار کردن ممکن نیست . این مسیر هم در موقع ایجاد گزارش در خود گزارش ذخیره می شه و همونطور که در اولین پست گفتم حتی با دستور CRV.ReportSource = Application.StartupPath + "\" + "Chart.rpt" هم نتونستم این مسیر رو به گزارشم بدم.
:گیج: امیدوارم که شما چند نفر عاشق کریستال ریپورت و وی بی دات نت مشکل من رو حل کنید.

In_Chan_Nafar
یک شنبه 29 خرداد 1384, 22:44 عصر
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

'If you are using a Strongly Typed report (Imported in
'your project) named CrystalReport1.rpt use the
'following:

Dim crReportDocument As New CrystalReport1()

'If you are using a Non-Typed report, and
'loading a report outside of the project, use the
'following:

Dim crReportDocument As New ReportDocument()

crReportDocument.Load("c:\myReports\myReport.rpt")

'Set the ConnectionInfo properties for logging on to
'the Database

'If you are using ODBC, this should be the
'DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the
'physical server name

With crConnectionInfo
.ServerName = "DSN or Server Name"

'If you are connecting to Oracle there is no
'DatabaseName. Use an empty string.
'For example, .DatabaseName = ""

.DatabaseName = "DatabaseName"
.UserID = "Your User ID"
.Password = "Your Password"
End With

'This code works for both user tables and stored
'procedures. Set the CrTables to the Tables collection
'of the report

CrTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the
'LogonInfo information

For Each CrTable in CrTables
CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo =
crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)

'If your DatabaseName is changing at runtime, specify
'the table location.
'For example, when you are reporting off of a
'Northwind database on SQL server you
'should have the following line of code:

crTable.Location = "Northwind.dbo." &
crTable.Location.Substring(crTable.Location.LastIn dexOf(
".") + 1)
Next

'Set the viewer to the report object to be previewed.

CrystalReportViewer1.ReportSource = crReportDocument


---------Access-------------
• If you are reporting off an Access database, then
specify either the 'ServerName' or 'DatabaseName'
to the 'ConnectionInfo' Object depending on
how you are connecting to Access.

For example, if you are connecting to Access
through ODBC, then set the 'DatabaseName' for the
'ConnectionInfo' object as follows:

With crConnectionInfo
.DatabaseName = "C:\mydatabase\mydata.mdb"
End With

If you are connecting to Access through OLE DB,
then set set the 'ServerName':

With crConnectionInfo
.ServerName = "C:\mydatabase\mydata.mdb"
End With




برای کسب اطلاعات بیشتر

http://support.businessobjects.com/library/kbase/articles/c2010371.aspl]

PalizeSoftware
چهارشنبه 15 تیر 1384, 00:45 صبح
ساده ترین راه تعریف یک DSN است که دیگه نیازی به معرفی دوباره به کریستال نیست

H_Ghaffarian
سه شنبه 01 شهریور 1384, 06:57 صبح
سلام
با تشکر از دوستان ، لطفاً اگه ممکنه یک نمونه کد از تعریف DSN برای کار با Access و کریستال ریپورت رو اینجا بزارید.

nazila_f
سه شنبه 19 دی 1385, 15:51 عصر
من از طریق همان connectioninfo مشکلم حل شد اما وقتی در شبکه آدرس کامپیوتر اصلی(سرور) را می دهم حتی ip را هم که می دهم با از من مسیر و username می خواد یعنی فقط در کامپیوتر Client مشکل دارم:گریه: :گریه: :گریه:

saeedsa
سه شنبه 11 مرداد 1390, 17:30 عصر
در اینجا دو حال پیش می آید یا گزارش subreport هست یا داکیومنت معمولی
ابندا باید داکیومنت گزارش و کانکشن اینفو را به توابع بدهد
نحوه پر کردن connectionInfo






ConnectionInfo ConnectionInfoRpt = new ConnectionInfo();
ConnectionInfoRpt.IntegratedSecurity = true;
ConnectionInfoRpt.DatabaseName = "database";
ConnectionInfoRpt.Password = "pass";
ConnectionInfoRpt.UserID = "user";
ConnectionInfoRpt.ServerName = SystemInformation.ComputerName.ToString();
Finassl rpt = new Finassl();



حالا نوبت به ارسال هم داکیومنت و کاننکشن است

ApplyLogOnInfoForSubreports(rpt, ConnectionInfoRpt);



تابع را فراخوانی می کنیم


private void ApplyReportLogon(CrystalDecisions.CrystalReports.E ngine.ReportDocument RptYears, ConnectionInfo sa)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table tablex in RptYears.Database.Tables)
{
tablex.LogOnInfo.ConnectionInfo.AllowCustomConnect ion = true;
TableLogOnInfo tablelog = tablex.LogOnInfo;
tablelog.ConnectionInfo = sa;
tablex.ApplyLogOnInfo(tablelog);
}
}



حال اگر فرم شما ساب ریپورت داشته باشد فرم ریپورت خود را به جای ارسال به تابع فوق به تابع زیر ارسال می نمایید




private void ApplyLogOnInfoForSubreports(CrystalDecisions.Cryst alReports.Engine.ReportDocument rpt, ConnectionInfo ConnectionInfoRpt)
{
Sections Sections = rpt.ReportDefinition.Sections;
foreach (Section section in Sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
var subreportobject = (SubreportObject)reportObject;
ReportDocument SubReportDocument = subreportobject.OpenSubreport(subreportobject.Subr eportName);
ApplyReportLogon(SubReportDocument, ConnectionInfoRpt);
}
}
}
}













امیدوارم تونسته باشم مشکلی را حل کرده باشم