晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
, H. k; \3 g. [# I+ `  L" o/ T- _2 W7 v* ?6 X
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
7 _" U4 A9 w: ?/ L$ R. T( i  T" q/ d$ ^# B
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别" m2 E% d7 U! o( Y/ ?0 q
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
- ?: F1 }9 ?' I  `4 W+ W3 Whttp://www.itwis.com/html/net/c/20100506/8234.html
2 P) S! S- c: i( C* d  w. Z
  ~6 @; c& {' g7 F( T7 E  A程序代码
! [: g& }2 `: y/ B% R8 C! ?1) public string[] Split(params char[] separator). E0 @% n* F0 ]6 s+ X5 I
2) public string[] Split(char[] separator, int count)
% u. l. Z0 ~* f% @8 G* h3) public string[] Split(char[] separator, StringSplitOptions options)
. \4 R& Q! Q" `) N' h4) public string[] Split(string[] separator, StringSplitOptions options)
8 g' B. ]7 L' X+ W$ x5) public string[] Split(char[] separator, int count, StringSplitOptions options)9 V$ A, N# v& ^- l- X" n" R4 {+ ]
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
9 M7 c( U: R4 t; S+ S9 `. x7 {, v. J- o! e
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):0 O0 ~) y0 m9 B+ ~% F' L  p& R2 b1 b
) E: ]3 M% j8 Q# Y2 j/ K8 |
1. public string[] Split(params char[] separator)
. M, u2 d; l* ~% O+ L' g; q( s0 U3 [! d4 Q# }+ r& ]
程序代码
1 ^; s' |' x4 u4 l! p& r2 zstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}! U6 h4 i2 @. B1 t. o! ~
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}+ Q; |3 y' P* M( L$ A: ]0 u$ e
" S' R  G: t) W+ @8 G* E
2. public string[] Split(char[] separator, int count)! }/ s2 c! V0 N; j' u9 E9 n" }# i

5 x6 L% R4 e! l  u 程序代码$ B# U( A5 H+ O8 e  k$ b
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}. U7 u  n, F) g, N3 ]6 N
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
- q7 [, s1 R+ I: H$ [# Y/ J$ p, G/ `6 ]8 W3 {' a
3. public string[] Split(char[] separator, StringSplitOptions options)
% p2 t& s. U  I+ F# ]
! k+ Q' v+ `+ i2 _6 V 程序代码& a9 w' g: p0 `
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
, u1 R' U# W/ D' n* C% Istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 K1 r' p" U' w( X- r9 z
) M& o# e% ^1 ~# i4 L& ~+ S
4. public string[] Split(string[] separator, StringSplitOptions options)
* V, y2 B- g1 X! z0 r8 N% _; _) G3 D
程序代码  r) C. B# v) u! d6 t
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! Z& z/ L, i+ `: ^1 n0 Sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 d  \; D# G3 G  b0 ~- e) ~7 A9 _& E; W+ E: h0 {5 o: N* J
5. public string[] Split(char[] separator, int count, StringSplitOptions options), f6 J, p( t# f: ]6 G3 n* n% F

2 L  }2 J: e. c2 r 程序代码
2 ^7 W* Y5 ~( _- ~string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" F# G( q( ~7 vstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 @9 }) X" ~2 E9 h
! h: u- ~  |5 D( G6 T' ^6. public string[] Split(string[] separator, int count, StringSplitOptions options)
: }' f4 y9 A2 d1 E5 O: i0 c9 \4 |3 p
代码
" T" r+ T) f, }; Ustring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素5 X8 K! f; D; U
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-24 07:17 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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