| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 577 人关注过本帖
标题:使用npoi将execl导入数据库报错...大神帮我看看谢谢
取消只看楼主 加入收藏
夜小四1314
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-15
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
使用npoi将execl导入数据库报错...大神帮我看看谢谢
private void btnDR_Click(object sender, EventArgs e)
        {
            string sql = "insert into Seat (CC_LoginId, CC_LoginPassword, CC_UserName) values (@loginId,@loginPassword,@UserName)";
            SqlParameter[] sp =
            {
                new SqlParameter("@loginId",SqlDbType.NVarChar),
                new SqlParameter("@loginPassword",SqlDbType.VarChar),
                new SqlParameter("@UserName",SqlDbType.NVarChar)
            };
            using (FileStream fs = new FileStream(@"D:\Code\20120822\ExeclDemo\bin\Debug\seat.xls", FileMode.Open, FileAccess.Read))
            {
                IWorkbook wk = new HSSFWorkbook(fs);
                ISheet sheet  = wk.GetSheet("seat");
                for (int i = 0; i <= sheet.LastRowNum; i++)
                {
                    IRow row = sheet.GetRow(i);
                    for (int c = 1; c < row.LastCellNum; c++)
                    {
                        ICell cell =row.GetCell(c);
                        sp[c-1].Value=cell.ToString();
                    }
                    SqlHelper.SqlHelper.ExecuteNonQuery(sql,CommandType.Text,sp);
                }
            }
            MessageBox.Show("OK");
        }

使用的是SQLHelper  ...
public  static int ExecuteNonQuery(string sql, CommandType type,params SqlParameter[] parameters)
        {
            
            using (SqlConnection conn = new SqlConnection(con))
            {
                if(conn.State == System.Data.ConnectionState.Closed)
                {
                    conn.Open();
                }
                using (SqlCommand cmd = conn.CreateCommand())
                {
                     = sql;
                     = type;
                    if (parameters != null && parameters.Length > 0)
                    {
                        cmd.Parameters.AddRange(parameters);
                    }
                    cmd.Parameters.Clear();
                    return cmd.ExecuteNonQuery();报错是...另一个SqlParameterCollection中已包含SqlParameter。
                }
            }
        }
搜索更多相关主题的帖子: 数据库 into private insert values 
2012-08-23 11:42
快速回复:使用npoi将execl导入数据库报错...大神帮我看看谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024624 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved