crystalReportViewer在Windows应用程序

我正在使用代码将ConnectionInfo发送到crystalReportViewer

private void button1_Click(object sender, EventArgs e) { ConnectionInfo myConnectionInfo = new ConnectionInfo(); myConnectionInfo.ServerName = "192.168.3.58"; myConnectionInfo.DatabaseName = "SHRK-Traffic"; myConnectionInfo.UserID = "sa"; myConnectionInfo.Password = "pass"; setDBLOGONforREPORT(myConnectionInfo); crystalReportViewer1.Visible = true; } private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo) { TableLogOnInfos mytableloginfos = new TableLogOnInfos(); mytableloginfos = crystalReportViewer1.LogOnInfo; foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos) { myTableLogOnInfo.ConnectionInfo = myconnectioninfo; } } 

我正在与这个代码在web应用程序,它工作正常..但在Windows应用程序,它显示错误

错误http://img.zgserver.com/c%23/104kymv.jpg

我收到一个错误

    您需要创建一个TableLogOnInfo对象,然后将它的ConnectionInfo对象设置为正确的信息,即:

      TableLogOnInfo loginDetails = new TableLogOnInfo(); loginDetails.ConnectionInfo.serverName = "ALFA1\\ACMSDB"; loginDetails.ConnectionInfo.UserID = "***"; loginDetails.ConnectionInfo.Password = "***"; loginDetails.ConnectionInfo.DatabaseName = "database"; loginDetails.ConnectionInfo.IntegratedSecurity = false; 

    然后继续将已配置的TableLogOnInfo对象添加到您的LogOnInfo集合:

      crystalReportViewer1.LogOnInfo.Add(loginDetails);