日期:2014-05-17  浏览次数:20436 次

excel数据导入sqlserver数据库中
如题怎么弄呢

------解决方案--------------------
bcp快速导入
------解决方案--------------------
1、把EXCEL文件上传到服务器上
2、连接该文件把数据写入数据集
3、循环数据集插入SQL中
------解决方案--------------------
excel导入sql代码

SqlConnection sqlcnn = new SqlConnection(sqlstr);
SqlCommand sqlcmm = sqlcnn.CreateCommand();
sqlcnn.Open();
sqlcmm.CommandText = "insert into T_student (classid,studentnum,studentname,shouji,qq) values(@classid,@studentnum,@studentname,@shouji,@qq)";
SqlParameter[] parameters = {
new SqlParameter("@classid", SqlDbType.VarChar,50),
new SqlParameter("@studentnum", SqlDbType.VarChar,50),
new SqlParameter("@studentname", SqlDbType.VarChar,50),
new SqlParameter("@shouji", SqlDbType.VarChar,50),
new SqlParameter("@qq", SqlDbType.VarChar,50)};

Stream s = File.Open(@"G:\专业知识\10级net3班信息表.xls", FileMode.Open, FileAccess.Read);
HSSFWorkbook workbook = new HSSFWorkbook(s);
HSSFSheet sheet = workbook.GetSheet("Sheet1");
for (int i = 0; i < sheet.LastRowNum; i++)
{
HSSFRow row = sheet.GetRow(i);
sqlcmm.Parameters.Clear();
sqlcmm.Parameters.AddRange(parameters);
for (int j = 0; j < sheet.GetRow(i).LastCellNum; j++)
{
parameters[j].Value = row.GetCell(j).StringCellValue;
}
sqlcmm.ExecuteNonQuery();
}
sqlcmm.Clone();
sqlcnn.Dispose();
MessageBox.Show("成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
------解决方案--------------------
探讨

引用:
bcp快速导入

bcp是什么控件 啊,没用过