已有56人关注
企业客户资源管理系统的frmCLAnalyse 不知是什么意思,请老师指导一下,万分感谢
发表在C#图书答疑 2010-09-05
是否精华
版块置顶:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CRM.SumManage
{
    public partial class frmCLAnalyse : Form
    {
        CRM.BaseClass.OperateAndValidate opAndvalidate = new CRM.BaseClass.OperateAndValidate();
        public frmCLAnalyse()
        {
            InitializeComponent();
        }

        private void frmCLAnalyse_Load(object sender, EventArgs e)
        {
            string P_str_sql = " {tb_ClientInfo.CStep} like '*'";  [font color=#FF0000]//此处是什么意思,引用的是那里的定义呀,右击转到定义,查不到,不知什么意思呀,请老师指导一下,万分谢谢。[/font]
            CReportViewer.ReportSource = opAndvalidate.CrystalReports("CReportCLAnalyse.rpt", P_str_sql);
        }

        private void tsbtnLook_Click(object sender, EventArgs e)
        {
            string P_str_sql = " {tb_ClientInfo.CStep} like '" + tscboxCLevel.Text.Trim() + "'";
            CReportViewer.ReportSource = opAndvalidate.CrystalReports("CReportCLAnalyse.rpt", P_str_sql);
        }

        private void tsbtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}





[font color=#FF0000]//我用静态的sql连接是可以显示出报表,但我的数据库连接是读取ini文件中的连接字符串的,数据库查询是封装了的,请问要怎么改才可以呀?

//以下是我的数据库封装的类。[/font]





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace IT部门管理系统
{
    class cls_dbOpSql
    {
                       
       

        #region  全局变量
        public static string Login_ID = ""; //定义全局变量,记录当前登录的用户编号
        public static string Login_Name = "";  //定义全局变量,记录当前登录的用户名
        public static string Mean_SQL = "", Mean_Table = "", Mean_Field = "";  //定义全局变量,记录“基础信息”各窗体中的表名及SQL语句
        public static SqlConnection My_con;  //定义一个SqlConnection类型的公共变量My_con,用于判断数据库是否连接成功      
        public static int Login_n = 0;  //用户登录与重新登录的标识      
        //public static int res = 0;
        #endregion

        #region  建立数据库连接
        /// <summary>
        /// 建立数据库连接.
        /// </summary>
        /// <returns>返回SqlConnection对象</returns>
        /// 
        public static string M_str_sqlcon;   //接收登录窗体传来的连接字符串
        public string conStr
        {
            set { M_str_sqlcon = value; }
            get { return M_str_sqlcon; }
        }

        public static SqlConnection getcon()
        {
            My_con = new SqlConnection(M_str_sqlcon);   //用SqlConnection对象与指定的数据库相连接
            My_con.Open();  //打开数据库连接
            return My_con;  //返回SqlConnection对象的信息                

        }
        #endregion

        #region  测试数据库是否赋加
        /// <summary>
        /// 测试数据库是否赋加
        /// </summary>
        public void con_open()
        {
            getcon();
            //con_close();
        }
        #endregion

        #region  关闭数据库连接
        /// <summary>
        /// 关闭于数据库的连接.
        /// </summary>
        public void con_close()
        {
            if (My_con.State == ConnectionState.Open)   //判断是否打开与数据库的连接
            {
                My_con.Close();   //关闭数据库的连接
                My_con.Dispose();   //释放My_con变量的所有空间
            }
        }
        #endregion

        #region  读取指定表中的信息
        /// <summary>
        /// 读取指定表中的信息.
        /// </summary>
        /// <param name="SQLstr">SQL语句</param>
        /// <returns>返回bool型</returns>
        public SqlDataReader getcom(string SQLstr)
        {
            getcon();   //打开与数据库的连接
            SqlCommand My_com = My_con.CreateCommand(); //创建一个SqlCommand对象,用于执行SQL语句
            My_com.CommandText = SQLstr;    //获取指定的SQL语句
            SqlDataReader My_read = My_com.ExecuteReader(); //执行SQL语名句,生成一个SqlDataReader对象
            return My_read;
        }
        #endregion

        #region 执行SqlCommand命令
        /// <summary>
        /// 执行SqlCommand
        /// </summary>
        /// <param name="M_str_sqlstr">SQL语句</param>
        public void getsqlcom(string SQLstr)
        {
            getcon();   //打开与数据库的连接
            SqlCommand SQLcom = new SqlCommand(SQLstr, My_con); //创建一个SqlCommand对象,用于执行SQL语句
            SQLcom.ExecuteNonQuery();   //执行SQL语句
            SQLcom.Dispose();   //释放所有空间
            con_close();    //调用con_close()方法,关闭与数据库的连接
        }
        #endregion

        #region  创建DataSet对象
        /// <summary>
        /// 创建一个DataSet对象
        /// </summary>
        /// <param name="M_str_sqlstr">SQL语句</param>
        /// <param name="M_str_table">表名</param>
        /// <returns>返回DataSet对象</returns>
        public DataSet getDataSet(string SQLstr, string tableName)
        {
            getcon();   //打开与数据库的连接
            SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr, My_con);  //创建一个SqlDataAdapter对象,并获取指定数据表的信息
            DataSet My_DataSet = new DataSet(); //创建DataSet对象
            SQLda.Fill(My_DataSet, tableName);  //通过SqlDataAdapter对象的Fill()方法,将数据表信息添加到DataSet对象中
            con_close();    //关闭数据库的连接
            return My_DataSet;  //返回DataSet对象的信息

            //WritePrivateProfileString(string section, string key, string val, string filePath);
        }
        #endregion

 

        }
    }
分享到:
精彩评论 3
小科_mrkj
学分:43 LV2
2010-09-06
沙发
读者朋友:
    您好,问题回复如下:
(1){tb_ClientInfo.CStep} like '*'是水晶报表中的查询语法,这个是固定的;
(2)关于通过INI文件动态设置数据库连接的实例,可以参考《C#范例完全自学手册》中相关例子。
wufayou
学分:0 LV1
TA的每日心情
第五天
2023-03-18 21:24:17
2010-09-06
板凳
已购买该书,过几天到货了,我再查看一下,谢谢。
wufayou
学分:0 LV1
TA的每日心情
第五天
2023-03-18 21:24:17
2010-09-08
地板
//首先把数据加载到内存表中
        public DataSet getDataTable(string SQLstr, string tableName)
        {
            getcon();   //打开与数据库的连接
            SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr, My_con);  //创建一个SqlDataAdapter对象,并获取指定数据表的信息            
            DataTable dtable = new DataTable();
            SQLda.Fill(dtable);
            return dtable; //[font color=#FF0000]此处报错[/font]
            con_close();    //关闭数据库的连接
        }

//再用报表的SetDataSource设置报表数据源


        private void frm_CReportBuy_Load(object sender, EventArgs e)
        {
            DataTable dtable = getDataTable("select  _autoNum, _buyDate, _name, _specifications, _price , _number, _supplyCompany from tb_buy order by _buyDate desc ", "tb_buy");
           ReportDocument reportDocument = new ReportDocument();
           reportDocument.SetDataSource = dtable;    [font color=#FF0000]//此处报错[/font]
           
        }  
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照