TinyMind
.net.cn
首页
资讯
文章
注册
登录
从Excel中读出导入sql server
wucf2004
关注文章
TinyMind专栏频道
/**/
///
<summary>
///
从Excel读取后导入sqlserver
///
</summary>
public
void
ReadExcel()
{
string
sql
=
"
Provider=Microsoft.Jet.OLEDB.4.0;DataSource=
"
+
Server.MapPath(
"
teachers.xls
"
)
+
"
;ExtendedProperties=Excel8.0
"
;
OleDbConnectioncnn
=
new
OleDbConnection(sql);
cnn.Open();
OleDbDataAdapteroda
=
new
OleDbDataAdapter(
"
select*from[教师$]
"
,cnn);
DataSetds
=
new
DataSet();
oda.Fill(ds);
cnn.Close();
int
count
=
ds.Tables[
0
].Rows.Count;
for
(
int
i
=
0
;i
<
count;i
++
)
{
Jzgjbxxmodel
=
new
Jzgjbxx();
model.JZGID
=
ds.Tables[
0
].Rows[i][
"
JZGID
"
].ToString();
model.JZGBM
=
ds.Tables[
0
].Rows[i][
"
JZGBM
"
].ToString();
model.XXID
=
ds.Tables[
0
].Rows[i][
"
XXID
"
].ToString();
model.XM
=
ds.Tables[
0
].Rows[i][
"
XM
"
].ToString();
model.YHID
=
ds.Tables[
0
].Rows[i][
"
YHID
"
].ToString();
model.SFZH
=
ds.Tables[
0
].Rows[i][
"
SFZH
"
].ToString();
if
(ds.Tables[
0
].Rows[i][
"
CSRQ
"
].ToString()
!=
""
)
{
model.CSRQ
=
DateTime.Parse(ds.Tables[
0
].Rows[i][
"
CSRQ
"
].ToString());
}
else
{
model.CSRQ
=
DateTime.Now;
}
model.XBBM
=
ds.Tables[
0
].Rows[i][
"
XBBM
"
].ToString();
model.MZBM
=
ds.Tables[
0
].Rows[i][
"
MZBM
"
].ToString();
model.WHCDBM
=
ds.Tables[
0
].Rows[i][
"
WHCDBM
"
].ToString();
model.ZCBM
=
ds.Tables[
0
].Rows[i][
"
ZCBM
"
].ToString();
model.JSZGBM
=
ds.Tables[
0
].Rows[i][
"
JSZGBM
"
].ToString();
model.DYXLBM
=
ds.Tables[
0
].Rows[i][
"
DYXLBM
"
].ToString();
model.ZZMMBM
=
ds.Tables[
0
].Rows[i][
"
ZZMMBM
"
].ToString();
model.BZLBBM
=
ds.Tables[
0
].Rows[i][
"
BZLBBM
"
].ToString();
model.RKZKBM
=
ds.Tables[
0
].Rows[i][
"
RKZKBM
"
].ToString();
model.GWZYBM
=
ds.Tables[
0
].Rows[i][
"
GWZYBM
"
].ToString();
model.DZXX
=
ds.Tables[
0
].Rows[i][
"
DZXX
"
].ToString();
model.BZ
=
ds.Tables[
0
].Rows[i][
"
BZ
"
].ToString();
model.SCBZ
=
ds.Tables[
0
].Rows[i][
"
SCBZ
"
].ToString();
if
(ds.Tables[
0
].Rows[i][
"
CJNY
"
].ToString()
!=
""
)
{
model.CJRQ
=
DateTime.Parse(ds.Tables[
0
].Rows[i][
"
CJNY
"
].ToString());
}
else
{
model.CJRQ
=
DateTime.Now;
}
if
(ds.Tables[
0
].Rows[i][
"
CJGZNY
"
].ToString()
!=
""
)
{
model.CJGZRQ
=
DateTime.Parse(ds.Tables[
0
].Rows[i][
"
CJGZNY
"
].ToString());
}
else
{
model.CJGZRQ
=
DateTime.Now;
}
if
(ds.Tables[
0
].Rows[i][
"
LXNY
"
].ToString()
!=
""
)
{
model.LBXGZRQ
=
DateTime.Parse(ds.Tables[
0
].Rows[i][
"
LXNY
"
].ToString());
}
else
{
model.LBXGZRQ
=
DateTime.Now;
}
(
new
JzgjbxxBLL()).Create(model);
}
ds.Clear();
}
优质内容筛选与推荐
>>
1、[BZOJ 1297][SCOI 2009]迷路(矩阵快速幂)
2、CodeForces 650A Watchmen
3、继承面试
4、SDN模拟器ONOS Install Guide
5、uploadify实战操作(二)
赞赏
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
阅读
好看
已推荐到看一看
你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
取消
推荐
我知道了
已取消,“好看”想法已同步删除
知道了
已推荐到看一看
和朋友分享想法
最多200字,当前共
字
发送
已发送
朋友将在看一看看到
确定
分享你的想法...
取消
分享想法到看一看
确定
最多200字,当前共
字
发送中
网络异常,请稍后重试
知道了
微信扫一扫
关注该公众号
0
│
收藏
│
举报