基本信息
源码名称:C# 数据打印 实例源码下载
源码大小:0.40M
文件格式:.zip
开发语言:C#
更新时间:2017-06-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using DLLFullPrint;//添加打印模块的命名空间
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TransferPrint
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string M_str_sqlcon = @"Data Source=127.0.0.1;Initial Catalog=db_mrsql;User ID=sa";
public static SqlConnection My_con; //定义一个SqlConnection类型的公共变量My_con,用于判断数据库是否连接成功
public string SQLstr = "select * from tb_YearD09"; //tb_YearD09,tb_distribution09
public string SQLTable = "tb_YearD09";
public DataSet DSet = new DataSet();
#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)
{
My_con = new SqlConnection(M_str_sqlcon); //用SqlConnection对象与指定的数据库相连接
My_con.Open(); //打开数据库连接
SqlDataAdapter SQLda = new SqlDataAdapter(SQLstr, My_con); //创建一个SqlDataAdapter对象,并获取指定数据表的信息
DataSet My_DataSet = new DataSet(); //创建DataSet对象
SQLda.Fill(My_DataSet, tableName); //通过SqlDataAdapter对象的Fill()方法,将数据表信息添加到DataSet对象中
My_con.Close(); //关闭数据库的连接
return My_DataSet; //返回DataSet对象的信息
}
#endregion
private void Form1_Load(object sender, EventArgs e)
{
DSet = getDataSet(SQLstr, SQLTable);
dataGridView1.DataSource = DSet.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
MyDLL.TakeOver(DSet);//向打印模块中的DLL文件传递参数
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}