我是Crystal Report的新手,我遇到了一個我無法弄清楚的問題。 因爲我無法在任何地方找到答案,所以我嘗試使用這種方法。防止在Visual Studio 2010的Crystal Report中登錄ODBC文本驅動程序
我正在使用Crystal Report,它使用ODBC數據庫和文本驅動程序作爲數據源。 此報告在使用獨立Crystal Report XI打開時非常完美。
當通過VS2010通過基本的c#程序打開它時,總是會提示輸入此DB的用戶名和密碼,儘管沒有這個。 因此,我無法訪問數據。
奇怪的是,可以通過編輯器中的「瀏覽字段數據」來訪問字段的數據。
有什麼我失蹤?
namespace CrystalReportsApplication1
{
public partial class Form1 : Form
{
private string reportPath;
private ReportDocument repDoc = new ReportDocument();
private FileInfo m_AssemblyCS;
private DirectoryInfo m_SolutionRoot;
public Form1()
{
InitializeComponent();
m_AssemblyCS = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
m_SolutionRoot = m_AssemblyCS.Directory.Parent.Parent.Parent;
reportPath = string.Empty;
}
private void bOpenReport_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = m_SolutionRoot.FullName;
openFileDialog1.Filter = "rpt files (*.rpt)|*.rpt|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
reportPath = openFileDialog1.FileName;
tbReportPath.Text = reportPath;
repDoc.Load(reportPath);
crystalReportViewer.ReportSource = repDoc;
}
}
}
}
任何幫助將是非常讚賞。
更新:
感謝您的快速響應。不幸的是,他們沒有幫助。我仍然得到錯誤。我試圖以下:
private void bOpenReport_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = m_SolutionRoot.FullName;
openFileDialog1.Filter = "rpt files (*.rpt)|*.rpt|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
reportPath = openFileDialog1.FileName;
tbReportPath.Text = reportPath;
repDoc.Load(reportPath);
foreach(Table table in repDoc.Database.Tables)
SetConnectionInfo(table.Name, "dds", "", "", "");
crystalReportViewer.ReportSource = repDoc;
}
}
private void SetConnectionInfo(string table, string server, string database, string user, string password)
{
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo = repDoc.Database.Tables[table].LogOnInfo;
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo = logOnInfo.ConnectionInfo;
connectionInfo.DatabaseName = database;
connectionInfo.ServerName = server;
connectionInfo.Password = password;
connectionInfo.UserID = user;
repDoc.Database.Tables[table].ApplyLogOnInfo(logOnInfo);
}
表的connectionInfos設置,但我仍然得到登錄對話框。
你的最後一個環節幫助。 Crystal Report似乎需要一個名爲SetBaseLogon的用戶名和PassWord的虛擬值。所以像「repDoc.SetDatabaseLogon(」UserName「,」UserPW「);」在加載報告之後做的伎倆。感謝您的幫助! – thomacco
非常好知道。不用謝。 –