有三个问题
水晶报表在每次调试的时候,打开它用crystalreportview看时候都会跳出"数据库登录窗口"
,有没有办法不让它显示,直接打开。水晶报表连接的数据库,只要换台电脑都需要重新调试好,即使用本地服务器打点,密码设置的一样也是如此,有没有办法写一段代码吧他所要登陆的服务器,账号,用户名以及密码事先设置好,不与所用电脑绑定,就例如
public SqlConnection conn = new SqlConnection ("server=.; database=money; uid =sa; pwd =snow1987")然后用  SqlDataAdapter sda4 = new SqlDataAdapter("update intable set 计费时间="+textBox1.Text, conn);
            DataSet ds4 = new DataSet();
            sda4.Fill(ds4, "bbbb");
Dataset导入datagridview一样的方法数据库中的数据,如何设置其小数的进位问题,比如一个数据乘法的结果是1808.72.我要他在数据库中显示为1808.80,第二位只要有数字就想第一位进位,并且再调用这个数据是用1808.80来计算。程序和数据库都在表格文档中,用的是vs2005和sq2005

解决方案 »

  1.   

    你的数据库连接字符应该保存在CONFIG文件中如:WEB.CONFIG 或 APP.CONFIG<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
      </configSections>
      <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=192.168.1.232;Initial Catalog=XXXDB;Persist Security Info=True;User ID=sa"
          providerName="System.Data.SqlClient" />
      </connectionStrings>
    </configuration>使用DATASET来填充报表的数据源            ReportDocument rptDoc = new ReportDocument();
                rptDoc.Load(Application.StartupPath + reportFileName);
                DataSet ds;
                ds = bll.GetList(sqlExpression);
                rptDoc.SetDataSource(ds.Tables[0]);            crystalReportViewer.ReportSource = rptDoc;
      

  2.   

    你应该采用了PULL模式直连数据库
    可参考
    http://www.cnblogs.com/babyt/archive/2008/10/09/1307346.html
    的解决方法
      

  3.   

    第一个问题修改下配置文件,第三个问题,你数据库用MYSQL,它会自动进位
      

  4.   


    Question 1 
    //**************************
    // Method 1
    //**************************  
    你可以将sqlconnection控件的loginprompt设置为false并且在连接字符串中给出:   
    UserID='username';password='******'
      
     
    1.   DataBase的Alias和DataBaseName最好不要设置为一样的。其中Alias是在下拉框中选择的你在ODBC或BDE中设置好的数据库别名;DataBaseName中是你自己填的一个虚拟的数据库别名(会出现在其它的数据库控件的DataBaseName属性的下拉框中),供其它的数据库控件连接用,以达到统一管理数据库连接的作用。   
    2.   连接数据库时,如果想避免弹出登陆对话框,先要设置DataBase的Params属性。共分两栏,第一行的第一栏填user   name,第二栏填相应的用户名;第二行的第一栏填password,第二栏填相应的密码。然后再将DataBase的LoginPrompt设为false。这样,Connected为True时就没有登陆对话框了。   
    3.   如果是你的密码不对,那......
    你的数据库连接字符应该保存在CONFIG文件中如:WEB.CONFIG 或 APP.CONFIG 
    <?xml version="1.0" encoding="utf-8"?><configuration> <configSections> </configSections> <connectionStrings> <addname="ConnectionString" connectionString="Data Source=192.168.1.232;Initial Catalog=XXXDB;Persist Security Info=True;User ID=sa" providerName="System.Data.SqlClient" /> </connectionStrings></configuration>Question 2: 
    //**************************
    // Method 1
    //**************************    //数据库连接,我是从WEB.CONFIG得来的,你可以像你上面写死。
            string connStr = ConfigurationSettings.AppSettings["lj"].ToString();
            SqlDataSource datasource = new SqlDataSource(connStr, "select * from yang");  //数据集,根据你的需求改SQL语句
            ReportDocument doc = new ReportDocument();
            TableLogOnInfo logininfo = new TableLogOnInfo();
            string path;
            //string bgnDate;
            
            path = Server.MapPath("report1.rpt");
            doc.Load(path);
            //强制登录数据库,我是从WEB.CONFIG得来的,你可以像你上面写死。
            string a, b, c, d;
            a = System.Configuration.ConfigurationManager.AppSettings[0];  
            b = System.Configuration.ConfigurationManager.AppSettings[1];
            c = System.Configuration.ConfigurationManager.AppSettings[2];
            d = System.Configuration.ConfigurationManager.AppSettings[3];
            logininfo.ConnectionInfo.ServerName = a;
            logininfo.ConnectionInfo.DatabaseName = b;
            logininfo.ConnectionInfo.UserID = c;
            logininfo.ConnectionInfo.Password = d;        try
            {
                doc.Database.Tables[0].ApplyLogOnInfo(logininfo);
                doc.Database.Tables[0].SetDataSource(datasource.Select(DataSourceSelectArguments.Empty));
                CrystalReportViewer1.ReportSource = doc;
              }
            catch
            {
                Response.Write("<script>alert('输出报表失败,请检查输入信息或网络!');</script>");
            }
    //**************************
    // Method 2
    //**************************  
      override   protected   void   OnInit(EventArgs   e)   
      {   
      //   
      //   CODEGEN:   This   call   is   required   by   the   ASP.NET   Web   Form   Designer.   
      //   
      InitializeComponent();   
      base.OnInit(e);   
              crReportDocument   =   new   CrystalReport2();   
      crConnectionInfo   =   new   ConnectionInfo();   
      crConnectionInfo.ServerName="mainline";   
      crConnectionInfo.UserID="cobb";   
      crConnectionInfo.Password="cobb";   
      crDatabase=crReportDocument.Database;   
      crTables=crReportDocument.Database.Tables;   
      foreach   (CrystalDecisions.CrystalReports.Engine.Table   crTable   in   crTables)   
      {   
      crTableLogOnInfo   =   crTable.LogOnInfo;   
      crTableLogOnInfo.ConnectionInfo   =   crConnectionInfo;   
      crTable.ApplyLogOnInfo(crTableLogOnInfo);   
      }   
      CrystalReportViewer1.ReportSource   =   crReportDocument;   
      }  
    //**************************
    // Method 3
    //**************************  
      
    你先到CR编辑环境用数据库专家,修改你的数据库连接属性。   
      在程序里,把你的CR添加到项目里,比如叫MYCR.rpt。   
      实例化一个报表对象MYCR   CR1   =   new   MYCR();   
      需要引入using   CrystalDecisions.Shared;   
      然后在程序初始化的时候写上   
      TableLogOnInfo   LInfo   =   new   TableLogOnInfo();   
      LInfo.ConnectionInfo.ServerName   =   "CE10";   
      LInfo.ConnectionInfo.DatabaseName   =   "CE10";   
      LInfo.ConnectionInfo.UserID   =   "sa";   
      LInfo.ConnectionInfo.Password   =   "";   
      for(int   i=0;i<oRpt.Database.Tables.Count;i++)   
      {   
      CR1.Database.Tables[i].ApplyLogOnInfo(LInfo);   
      }   
          
          Question 3: 
    //**************************
    // Method 1
    //**************************  
    select   convert(numeric(8,2),@num)+0.01   from   table   
      @num为字段名//**************************
    // Method 2
    //**************************  
    double   dValue   =   0.2356;   
    double   result   =   System.Math.Round(dValue,2);   
        
      ===>   0.24    
      
    //**************************
    // Method 3
    //**************************  
    double d = 12.341; 
    double r = Math.Ceiling(d * 100) / 100; 
    Console.WriteLine(r); 
    //**************************
    // Method 4
    //**************************  
    public static double Round(double input)
    {
        string str = input.ToString();
        if (str.Length - 1 - str.IndexOf('.') == 2)
            return int.Parse(str[str.Length - 1].ToString()) > 5 ? Math.Round(input, 1) : Math.Round(input, 1) + 0.1;
        return input;
    }
    Note -- Pl. access below website for more information//**************************
    http://hi.csdn.net/home.html
    http://community.csdn.net/  
    //**************************
      

  5.   

    今天我也遇到了这个问题,研究了下,原来是绑定数据源到rpt文件时绑定了Dataset,这样不行,必须得绑定DataTable
    Testrpt.SetDataSource(ds.Tables[0]);
    我的水晶报表的数据库连接字符串都是在DataAdaper向导中直接写,把密码也写在里面,连接上了,把字段取出来了,以后就不用去管它了,再在后台绑定数据源就OK了
      

  6.   

    这是VS2003里面的一个BUG吧,记得以前数据集里面加个字段,要更新数据源好多次才会更新成功的
      

  7.   

    lintf1986太谢谢你了!
    Testrpt.SetDataSource(ds.Tables[0]);(这里我也是忘了填充!!,搞了我一上午)