易截截图软件、单文件、免安装、纯绿色、仅160KB

c#中高效的excel导入sqlserver的方法

本文转自:http://blog.csdn.net/jinjazz/archive/2008/07/14/2650506.aspx
    将oledb读取的excel数据快速插入的sqlserver中,很多人通过循环来拼接sql,这样做不但容易出错而且效率低下,最好的办法是使用bcp,也就是System.Data.SqlClient.SqlBulkCopy 类来实现。不但速度快,而且代码简单,下面测试代码导入一个6万多条数据的sheet,包括读取(全部读取比较慢)在我的开发环境中只需要10秒左右,而真正的导入过程只需要4.5秒。
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //测试,将excel中的sheet1导入到sqlserver中
            string connString = "server=localhost;uid=sa;pwd=sqlgis;database=master";
            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
            if (fd.ShowDialog() == DialogResult.OK)
            {
                TransferData(fd.FileName, "sheet1", connString);
            }
        }
        public void TransferData(string excelFile, string sheetName, string connectionString)
        {


相关文档:

C# 用SQL新建数据库

1. 程序如下:
         string str = "Create Database " + "DBname";
         string con = "Data Source=10.0.0.249\\sql2005;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=sa";
   &n ......

java中的super与c#中的base


C#中对base的解释(引自MSDN):
base 关键字用于从派生类中访问基类的成员:
调用基类上已被其他方法重写的方法。
指定创建派生类实例时应调用的基类构造函数。
基类访问只能在构造函数、实例方法或实例属性访问器中进行。
从静态方法中使用 base 关键字是错误的。
在本例中,基类 Person 和派生类 Employee 都有一个 ......

IBatisNet SQL Server的float类型转换为c# float出错

今天写一个商品的修改功能时遇到的问题
商品中重量 weight 的数据库(SQL Server2005)类型定义为 float
在mappings 中转换为c#类型的一句为
<result property="Goods_Weight" column="Goods_Weight" type="float" dbType="float"/>
按理说这个 float 是一样的,转换完全不会出现问题,
实际程序运行时,系统报错 ......

xml post(C#)

xmlpost by HttpWebRequest:
protected string PostXmlToURL(string url,string data)
{
    HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(url);
    hwr.Method = "POST";
    Stream stream = hwr.GetRequestStream();
    StreamWri ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号