本文主要是介绍微软自带报表rdlc使用之绑定数据源,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//绑定数据
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fcw.RDLC
{
public class SQLHelper
{
public static SqlConnection conn = null;
public static SqlCommand cmd = null;
public static string connstr =System.Configuration.ConfigurationSettings.AppSettings[“Connstr”].ToString();
public SQLHelper(){ }#region 建立数据库连接对象/// <summary>/// 建立数据库连接/// </summary>/// <returns>返回一个数据库的连接SqlConnection对象</returns>public static SqlConnection init(){try{conn = new SqlConnection(connstr);if (conn.State != ConnectionState.Open){conn.Open();}}catch (Exception e){throw new Exception(e.Message.ToString());}return conn;}#endregion#region 设置SqlCommand对象/// <summary>/// 设置SqlCommand对象 /// </summary>/// <param name="cmd">SqlCommand对象 </param>/// <param name="cmdText">命令文本</param>/// <param name="cmdType">命令类型</param>/// <param name="cmdParms">参数集合</param>private static void SetCommand(SqlCommand cmd, string cmdText, CommandType cmdType, SqlParameter[] cmdParms){cmd.Connection = conn;cmd.CommandText = cmdText;cmd.CommandType = cmdType;if (cmdParms != null){cmd.Parameters.AddRange(cmdParms);}}#endregion#region 执行相应的sql语句,返回相应的DataSet对象/// <summary>/// 执行相应的sql语句,返回相应的DataSet对象/// </summary>/// <param name="sqlstr">sql语句</param>/// <returns>返回相应的DataSet对象</returns>public static DataSet GetDataSet(string sqlstr){DataSet ds = new DataSet();try{init();SqlDataAdapter ada = new SqlDataAdapter(sqlstr, conn);ada.Fill(ds);conn.Close();}catch (Exception e){throw new Exception(e.Message.ToString());}return ds;}
这篇关于微软自带报表rdlc使用之绑定数据源的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!