晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件6 m: Q* C+ [/ K! K7 d) _
# p. H. Z8 s1 o
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码( H; w' u' L6 K7 G

  X% s& W0 e% v) x4 \* F对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
4 F3 C; j3 {( _/ O, Qhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看) ]1 w0 c2 A+ o4 G4 D
http://www.itwis.com/html/net/c/20100506/8234.html% Z" z. f& Y/ a4 Y

7 D9 Q% z$ i5 [  x! G程序代码
& y3 m- H6 C4 p" N1) public string[] Split(params char[] separator)
9 c* u0 h5 `7 J7 @# B2) public string[] Split(char[] separator, int count)
& A% ]! j+ G8 A9 M3) public string[] Split(char[] separator, StringSplitOptions options)1 z. R: L- s/ ~- @% q: z1 F
4) public string[] Split(string[] separator, StringSplitOptions options)5 l5 ?1 g( d8 D
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
* x- G! V6 Y1 t& y1 f6) public string[] Split(string[] separator, int count, StringSplitOptions options)
0 X( _7 O! b" C" s3 g3 V) \$ y$ d3 h  R2 X. x: M* l" x
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):; \3 j0 \  V. b4 L

3 q5 c6 o* @6 R- R1. public string[] Split(params char[] separator)4 @3 I9 _: k. d: ?( g$ U
/ G$ d9 f1 ~1 z# w/ ~
程序代码
, h# }$ \; Y2 _6 E# f. G; N( e# }string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
6 }& I% ^: G; Sstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, B& G% H7 x( z" j6 Y; h) \' J( G4 O& ?- I& K
2. public string[] Split(char[] separator, int count)/ y% T$ [& m5 I, j) f3 X
' m( ^/ `% n6 c1 W! j/ {' |0 J
程序代码
# B4 c: X" x8 t$ Ustring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}: o/ r/ x; f: e
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
* F2 H7 H9 {0 H3 Y0 p  q
3 X3 }2 v3 |: }" n3. public string[] Split(char[] separator, StringSplitOptions options)
; l4 d7 ~2 F3 t( b  ?+ L/ L. s3 T
程序代码# v3 o2 C8 V+ M  F, z/ O/ l
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; c, S) c/ o0 L( b7 s1 Cstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& N1 K, _$ M* m. Y; p3 ?

2 @: S! I8 c% q5 |1 p# {' f; K4. public string[] Split(string[] separator, StringSplitOptions options)
& q+ A) N9 p( h! h
* a) M9 X  q5 d  |' Y0 Q8 u 程序代码
5 f/ m+ G& x+ y* astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 r0 J. `8 n" c! i& E9 ~
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: D$ r; u& N1 l+ T4 }) h4 K
( I* o: W! _  P( d+ T# F: T3 ]
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
4 \! a9 l# U& P5 i/ ^& S5 y4 X/ B) {0 q( T& U5 t/ ~
程序代码
$ l# f) g2 b9 Z. H. o" qstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
% i! [- l* n+ O6 Pstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( \9 c. X3 ^+ [- r: E$ `9 K
/ Z9 W7 X6 g$ }! v- K6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 w( f! H: ?( T" E  A+ Q8 U  f0 z- v+ g
, T+ l. Z+ z/ J1 H3 `' _代码3 ~7 i- L% ?# O" R2 u* {8 W3 Z2 T6 I
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素& b7 |; `/ W2 y: P4 O' A2 A; u7 i
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 20:44 , Processed in 4.064609 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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