晨鸟科技
标题:
升级程序开发——读Web.config、执行Sql脚本
[打印本页]
作者:
Star
时间:
2011-2-18 17:28
标题:
升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
2 R. T0 W& f3 T( E3 i; H8 L8 V2 k4 D
9 ^9 x! u1 i& v* Z+ d5 P
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
: e. g: a& C. w! A
3 `2 O' [& a) O" c7 E/ ]
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者:
Star
时间:
2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
" S* r2 x% }9 B6 ~4 `* Z2 L4 e' m
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者:
Star
时间:
2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
6 d5 p. V' B! }# d: p7 ]5 C5 L/ P! I
http://www.itwis.com/html/net/c/20100506/8234.html
" v) _' f$ [; m0 x; W1 i
5 y* D3 R% n2 u' U! Y( D
程序代码
, E- ~ J+ {9 R7 Y9 Q) J
1) public string[] Split(params char[] separator)
7 B! k2 ^ C" {% q' V
2) public string[] Split(char[] separator, int count)
2 |; Y: Z( i7 e
3) public string[] Split(char[] separator, StringSplitOptions options)
0 M1 g) G* f! z/ z
4) public string[] Split(string[] separator, StringSplitOptions options)
- _9 w* e0 u+ n
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; A) h5 U( ?% |
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) G8 F0 @! G, ]0 q$ `$ P
" d3 h9 p. I0 J1 A) V6 }
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
$ `7 b1 R7 _3 l1 m7 A8 A
- f2 s( ~4 `$ p3 [" u+ k. [
1. public string[] Split(params char[] separator)
9 y$ \' l. X5 O6 B/ A& s$ i
. ?' _9 d8 D2 G% d3 H3 R' y
程序代码
2 x% C6 h: r7 Z5 ^( P) Z$ a* W
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
! ?! M# i O7 h4 z/ }
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
2 p% s0 W8 K: [" \* w
; n0 c# y: {1 g: T7 a+ s; y) l
2. public string[] Split(char[] separator, int count)
, J8 W1 r* `/ g$ X2 T
" |# c- t4 E2 z0 Q$ P! `
程序代码
% C3 I6 ?7 `+ {# V/ B. U
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
! l( k$ H: v* Z% u- `$ Y5 d
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
5 B0 G8 l, I, z+ E8 f q; l+ `
, H) ?: C: B( k& f- d4 r# M* X
3. public string[] Split(char[] separator, StringSplitOptions options)
$ S6 A+ w( P7 p0 V0 w
3 E e! s, {! U( y
程序代码
% M9 g# M0 m) N- v+ y! o! l) F
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
1 i* e6 A9 F- U2 J
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ s* Q. `6 k2 Y% K( z& H
8 }$ f# T. d) p2 l* W/ L
4. public string[] Split(string[] separator, StringSplitOptions options)
$ ^8 f) v3 d) W. ^: ~: x6 Y
' ]7 W. y5 n" e h7 }7 b5 ^
程序代码
4 z+ L3 a: C8 t6 F$ z% S8 M
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
4 T! m$ ^8 H+ {3 _- r9 F
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ t4 { X6 i- q4 \' n
6 _2 I8 y) }. e+ @7 R# L. Z
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
5 t# [& P+ g. h/ f$ t% ?
6 x8 c8 Q( `* X; y% c% s+ Z( A7 e/ H& g
程序代码
7 P0 D9 x {6 E1 q6 B. R: @
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! n8 A. W4 f. q
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 |" j3 Z# y0 |! u) P
1 [7 Q9 a6 C( B( k
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
* B/ _% r. ^& k2 N' x
7 R2 P+ g# x3 [5 z& ~$ V6 [* y
代码
- a; T$ } c# m1 }9 D
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 Z+ N/ J( H# m. A5 K
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/)
Powered by Discuz! X3.2