晨鸟科技

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

作者: Star    时间: 2011-2-18 17:28
标题: 升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
- j  O4 w( j+ A7 ~
' S5 n7 e" X, o4 j$ S- W2 w读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码! Z" H! d0 b* L* e
  m0 v% G* P- b6 W9 j( {1 O" a
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者: Star    时间: 2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( Q6 J* h& f( ^) [http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者: Star    时间: 2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
8 n6 e6 C8 J( b8 x! f: g$ khttp://www.itwis.com/html/net/c/20100506/8234.html$ y; }7 P/ O- G3 ]5 c

! g6 z  Y& A9 Q. v# j# @8 r程序代码
$ u* r* A! ~) h1) public string[] Split(params char[] separator)
8 s! d' z8 |' c+ z: i& S2) public string[] Split(char[] separator, int count)  j1 B1 b; y  ^/ Y
3) public string[] Split(char[] separator, StringSplitOptions options)
; c* c4 o( X  q  [4 F  g4) public string[] Split(string[] separator, StringSplitOptions options)7 w! l8 b) Q- D
5) public string[] Split(char[] separator, int count, StringSplitOptions options), M; Y* n, m0 V% a) k
6) public string[] Split(string[] separator, int count, StringSplitOptions options)2 R+ N4 J2 Q5 s, i7 Q

2 U  o' s5 Q5 o+ H" d: `2 B. ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, a) k: D( K( M
- D) J6 J# ^; K' a3 H+ H; f
1. public string[] Split(params char[] separator)4 @0 F% y9 W4 X  E9 ]% \: w* }
3 \7 M# Y/ X! o  C1 |: n7 ~5 {8 I
程序代码# F" t0 R8 H- v! ]
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
( ^7 P7 g2 M# q* G0 ]string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}! S2 s9 d$ \3 s$ e! j& f9 D
  x: S$ ^$ s( E' _  g9 a
2. public string[] Split(char[] separator, int count)
+ z1 j6 W8 g: Q! `3 C6 \2 h
& ]( }$ _9 l" h# b- y6 m% a0 j 程序代码
5 s6 ~. G7 X; m8 C1 r5 ~/ A4 jstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
: W/ R. J( E# N" b' }" g* \string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
( L& [- ~2 E5 `3 l8 U( D: S; {3 I/ y8 x7 Y- J1 U4 |; c$ w  W7 ^1 q6 e( X
3. public string[] Split(char[] separator, StringSplitOptions options)
8 _! a+ T# M' l7 m' I4 S
( \! b/ Q% s  T' l# N' v4 X! R 程序代码& O2 ~  Q4 o( e, h4 w5 G  m+ z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素" z& D! `8 z) G. n; U/ I# p
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& J5 n2 u+ {4 z7 H# F/ k! v

; y; j3 v& h1 m: d5 z4. public string[] Split(string[] separator, StringSplitOptions options)
8 K$ E0 ?% U, l& b1 \3 e  d' Z. ^+ D3 Y( Q  y  p( b7 m  c
程序代码$ Q) a, N4 ]; J1 R) [3 g  @/ m
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, P" }; |/ K: C  z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* O. \/ G! O, E* X- x/ O+ h  X7 X
: J. Y3 H1 J! U* ~+ C- W: }: n8 l5. public string[] Split(char[] separator, int count, StringSplitOptions options)" N' e  c! X' E0 v% ~1 T

" P. U  v8 h5 e3 t) Z, I- C0 d 程序代码: w1 P; W0 L$ d8 H' T, b1 M
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
" b; E, q. W* v" ]string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
! f. `6 o+ g% T$ y% _  }/ w
% q- Q. U& Y7 X$ r% H2 l6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 V4 Z) T& x; v& Q+ m4 D4 L6 s7 v( H; K
代码  W9 d6 |8 U9 o; I
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素$ g; R/ H" n; |1 v
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素




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