C#将数据保存到Ex cel 中 第一步:首先添加两个组件: 打开解决方案资资源管理器,右键点击“引用”,选择“添加引用” 添加第一个引用: 再添加第二个引用: 第二步:引用命名空间: using System
Reflection;//这个命名空间是定义缺省值 第三步:界面设计(参考): 第四步:代码示例(仅供参考): /* 代码总有不完善之处,仅供参考 如有错误,敬请谅解 */ using System; using System
Collections
Generic; using System
ComponentModel; using System
Data; using System
Drawing; using System
Linq; using System
Text; using System
Windows
Forms; //引用连接数据库的命名空间 using System
SqlClient; //引用定义缺省值的命名空间 using System
Reflection; using System
Runtime
InteropServices; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //在窗体加载的时候当定数据 this
dataGridView1
DataSource = sqlconnection(); } //连接数据库获取相关数据 public DataTable sqlconnection() { //字段拼接 string str