晨鸟科技
标题:
升级程序开发——读Web.config、执行Sql脚本
[打印本页]
作者:
Star
时间:
2011-2-18 17:28
标题:
升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. |# j$ L$ [! _) x0 h
1 P# J7 {7 f+ }+ v8 Q- x
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 t1 I8 x9 o$ S4 h5 O) C
) G, W7 `% i/ b
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者:
Star
时间:
2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
" Z* y) H+ w- S/ J
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者:
Star
时间:
2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
% @! p% a2 F( N+ i
http://www.itwis.com/html/net/c/20100506/8234.html
: _0 P( F% L, G/ g
* [7 A% c; ^, A% M# i
程序代码
" j" w+ n9 X" d, m
1) public string[] Split(params char[] separator)
2 m, r1 a6 @# B( C8 x6 M) N: X
2) public string[] Split(char[] separator, int count)
2 n4 R8 B) V; f( g* X3 n( s% p1 _9 j4 W
3) public string[] Split(char[] separator, StringSplitOptions options)
6 S7 [. S) |- u0 U( P+ ^
4) public string[] Split(string[] separator, StringSplitOptions options)
/ e4 ~! l! l6 J% K' X$ T4 C
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
7 I0 R( u# K+ W) N# f; v: V
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
* A2 e" W$ |( `) K( p1 X
6 {3 E3 i/ w8 R- N1 B
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
' H# I4 J2 m$ ~% g& ^
& ~7 M k+ U+ [7 O8 H
1. public string[] Split(params char[] separator)
/ a; x) n$ G) E
8 q& W& u! h9 h$ j+ l) X
程序代码
1 B" l4 D% E3 w, V
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
' u, m. F% Z. ?# C5 {7 r* z
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
) m) h c8 n9 S! k: I
q" @, }% }1 {- u+ x$ K- D6 N
2. public string[] Split(char[] separator, int count)
/ A% L' E3 z8 f( L- u( s
' U0 F) Y* K7 D ^" N; T) j
程序代码
5 X& _. s% g" d1 a' e U7 t
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
9 I# R2 ?6 y1 [, r+ E, U
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
! r3 f w+ C+ ]* V) p, N) B4 i" I+ e
; _/ v& h/ m ~3 h K
3. public string[] Split(char[] separator, StringSplitOptions options)
8 P8 V6 l4 i2 J8 w. y
1 Y4 z! T5 d/ O8 H
程序代码
7 f" {' H$ S' K
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 P/ @' f P' O: E" S& Q6 n
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ {2 s% D4 B: c1 ~. {2 q0 a7 s
( t6 k& P( |, o+ r- v* S3 o9 c
4. public string[] Split(string[] separator, StringSplitOptions options)
9 i2 ?' t2 }' M3 }' j
( U! [0 s+ b! X9 \
程序代码
% H5 u) r- g0 Q5 B- u
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
+ Q. s6 k5 g) E. U% z4 @0 m" I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
" r$ ]2 Y: G9 \' H
' U3 ~" t0 m9 K1 H; R
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
1 }" F$ c* A! t3 H# P
) c, k$ G- X/ v! I/ O% k
程序代码
7 c) _$ @: }8 @* R* O
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
' c- k$ V7 C% Z2 f
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ f5 X( l, @6 Q
8 d* q7 }1 j3 ^% n8 e% t: m3 r% H
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
# l* b- _, x% `3 G# r u$ g% e% v
# ~* f% u0 ~4 ]9 v) p7 @- W- h- t% X
代码
, H; [8 u+ X; C
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ V4 |( y. T' j; |
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/)
Powered by Discuz! X3.2