晨鸟科技

标题: 升级程序开发——读Web.config、执行Sql脚本 [打印本页]

作者: Star    时间: 2011-2-18 17:28
标题: 升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件8 P" x2 q# ]2 F

' n. D. `- l( C; \读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码7 |& ?7 h" K" G1 |7 L
- P9 m- i' z: N9 g, G: B. V
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者: Star    时间: 2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
% X0 G! c1 k! W9 r( ?' A3 }- R/ Ehttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者: Star    时间: 2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看- I. ^7 G: k% r! N2 I) g
http://www.itwis.com/html/net/c/20100506/8234.html; t! t# Y- m% e+ \0 r

9 Z% J7 r* k. G$ N  M程序代码
' w( _  i1 E" }" s: p+ I1) public string[] Split(params char[] separator)! e3 s+ B4 ]7 t- ?6 k  o1 A0 y
2) public string[] Split(char[] separator, int count)2 ?; ?6 O6 r! ?% g, X1 p1 y
3) public string[] Split(char[] separator, StringSplitOptions options)/ ~; z( a3 o1 H% h! Z7 W% W
4) public string[] Split(string[] separator, StringSplitOptions options)0 [& y" ~# I. s% f, n1 G3 J3 M
5) public string[] Split(char[] separator, int count, StringSplitOptions options)) R3 {" o3 |% N  Q! w  U9 v) G
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
9 y, X) d8 n: x
  Q6 I+ q- o& V/ K下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
7 a- t+ \: I0 {. F( q4 \; U- b' M5 v- b& J
1. public string[] Split(params char[] separator)
+ k+ g: ^4 k* u) l8 U! i4 ^) G
. ~. m& g9 B5 ^' F/ v! q 程序代码' K  ^( @: b; b, o5 C' ?% p( ?6 Y& B
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}. A. w) @3 C6 n; x6 y; S2 f! v
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
7 ]# D  ]2 E5 [0 ~/ f! D* P. G
2 a; y* v1 b* j- p& ~2. public string[] Split(char[] separator, int count)
( H5 x: u) N" N- S8 O; f7 `
( z& O) b7 Z6 C7 g& C2 L$ z 程序代码
1 k  m5 Z- t' o' G0 O+ nstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
9 b4 y) Y( C. C2 @2 i2 Gstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
6 E* H. D) d4 v
) D* r5 s, w! Y% l$ v7 m3. public string[] Split(char[] separator, StringSplitOptions options)
# I( y  V3 v& |* Y9 Y; j2 A0 U+ F/ b
, |) \. l' Q& y( [6 D& ^4 _ 程序代码
9 t5 h( D: V: n. T$ Z% f) Mstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
$ R7 w. O0 f& l7 \* Rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" p+ X- D/ q& \- R8 p9 B

2 N( Y4 w* V7 E9 r% M, i4. public string[] Split(string[] separator, StringSplitOptions options)
$ n8 C& Z+ K# J/ f' {
4 p* u" ]9 H8 }3 o2 v3 q 程序代码
9 v$ E# k% G6 {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
( ?- V7 I: D: z# r) A# }string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) ~/ T) k! X! I% b+ ~- m1 c) M0 X; u9 W

, o* e8 t0 a  {* V5 `4 \; C) {5. public string[] Split(char[] separator, int count, StringSplitOptions options)0 a; v$ z* V( t$ \, e) \

6 i$ o( Q! S% ] 程序代码! Z8 @. O: a* o2 L( \" ?3 z+ y
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 J) Z1 ^3 w" V' X& dstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 q6 p7 p' W7 u5 {+ B7 S' B- w1 p3 W7 f9 S
6. public string[] Split(string[] separator, int count, StringSplitOptions options)( F* R2 u+ S# Y( m9 |+ |& L
0 Z) H( ]6 A! W) `
代码
, Y  P! Q4 r6 \0 y1 t$ Rstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! b, {; R  L5 f, N3 X' m/ D5 u
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素




欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/) Powered by Discuz! X3.2