晨鸟科技

 找回密码
 注册
搜索
查看: 14071|回复: 3
打印 上一主题 下一主题

升级程序开发——读Web.config、执行Sql脚本

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
0 J1 [" b! N, S3 o& ~' n2 C: N% T. c4 k1 R6 Z
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码0 c( U. G1 V8 g! l  ^3 t$ o4 c
  i4 B* p9 X: s$ N4 {7 P
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
* {. I% _5 i. W: G% g# L3 S: dhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
* `& ^5 ^; F0 B" ?& I6 Y: `3 X/ Xhttp://www.itwis.com/html/net/c/20100506/8234.html0 l' `9 \" U( @4 ?3 h. X

  \5 _0 p# B* ]程序代码
1 l- q' A* U9 J- I  X1 r4 F1) public string[] Split(params char[] separator)
$ j# |; F! A/ W5 t, l! }- P2) public string[] Split(char[] separator, int count). f; i$ |4 G+ M. [
3) public string[] Split(char[] separator, StringSplitOptions options)! @3 Z8 Q9 J# ^# c9 F$ I- z
4) public string[] Split(string[] separator, StringSplitOptions options)
+ T6 V- \6 O( ?5) public string[] Split(char[] separator, int count, StringSplitOptions options)
! e* a( o6 }) A* I# j6) public string[] Split(string[] separator, int count, StringSplitOptions options). b, B* O; P6 O7 d

2 p" i4 T, e% D下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
* x/ K% f2 I# V' I9 h
2 V; S& Q/ O& K  L6 |1 \1 g- h1. public string[] Split(params char[] separator)
" v, o' A% M0 J" p# F  c+ y& B- `% v3 d* H
程序代码
# u8 A- Z8 \! G: M1 Astring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}& j. `  l) X7 y( E8 t2 I" G$ c
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}" E! d9 S  v- l& h  U! X5 o
' {" C7 b8 F+ t" n4 Q
2. public string[] Split(char[] separator, int count)
- J. p  `$ G! M* B; ~
* n* R) c. d( L5 } 程序代码& b) e2 X6 D4 x6 W3 f4 u) ?
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
& M- W' n* x, C6 g! \( Y  `" vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
& t( a/ p9 Z: p# }0 Z
* G7 ?* q. C$ C+ ?, g3. public string[] Split(char[] separator, StringSplitOptions options)
" ~5 b4 o8 i) ], n. F4 r) D, O* n- n( D. J/ C: ]6 B% {: S
程序代码
/ q  I" s* x, R2 f. N3 ?# l3 u8 @7 Vstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; U% w) B/ \8 n& e5 m
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 Q$ h% t- o' ^5 z  q; y! j2 T
$ x1 d# q& @# D' H- _% I4. public string[] Split(string[] separator, StringSplitOptions options)) o2 h: u: Y! T( f; V0 d
6 b7 c4 w1 k7 Z: _5 R" O
程序代码
3 U2 K8 h& i* p) q! B7 astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 S& R2 }- v; ?$ ?3 E3 Rstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 H, p! p# e; ?" t* [/ r
  g+ L0 {8 E2 k7 p( X$ {+ ?; M
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
$ D4 f- B  x  g6 u! }" U4 [
: g3 U: o8 Q" T" A 程序代码
* `# X2 h% P5 c8 wstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
& C# r5 M: K; p& w7 |" l7 A7 p0 Lstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 J& u2 [* s+ d" {3 S- D$ _
8 p2 `# e/ W/ M
6. public string[] Split(string[] separator, int count, StringSplitOptions options)1 \  D, v2 K- \1 D! ~
! |' P6 z8 z/ k$ @/ ?" [# i
代码
6 f: F1 K+ ~1 v4 ^4 e( rstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素% O- b+ z8 i+ G3 M9 Z3 l
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|晨鸟科技 ( 沪ICP备09012675号 )

GMT+8, 2026-2-26 21:45 , Processed in 6.067615 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表