晨鸟科技
标题:
升级程序开发——读Web.config、执行Sql脚本
[打印本页]
作者:
Star
时间:
2011-2-18 17:28
标题:
升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
8 z) m: x+ E1 o4 i& u, s# T, ]
$ c3 {' Z6 o$ z5 P
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
9 A& z6 U6 {( p# C* o: \ m) ^+ }: G8 Y
X4 T$ v+ D6 `" t
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者:
Star
时间:
2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
1 R% m) F4 V7 n7 u0 e, [
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者:
Star
时间:
2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
# A) [. k+ Y+ e. B0 N( I
http://www.itwis.com/html/net/c/20100506/8234.html
6 D* b: A# d9 e' {
8 O' @, t7 }6 S" K* J
程序代码
4 ?/ v: Y; c- k' Y
1) public string[] Split(params char[] separator)
' E+ A7 i# @( I8 d& @% o
2) public string[] Split(char[] separator, int count)
9 N) u w1 k3 ~
3) public string[] Split(char[] separator, StringSplitOptions options)
% v6 d1 @; T) S! |, ]3 i
4) public string[] Split(string[] separator, StringSplitOptions options)
1 M$ ^' w# _5 o- k. K( v
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& J( m7 ?' I3 I$ d7 U9 s: x1 \
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
- ~! E$ Z+ A! L a2 x8 ]( Y
) n. f) R5 d& y
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
6 }, X# C; ^& U, u, I( b! M
4 Q1 h4 [0 s4 j
1. public string[] Split(params char[] separator)
! t* h% K( v+ f4 j x. w+ n4 l4 L1 w
( M8 H5 q' b$ E7 c) [
程序代码
1 j5 z% Y. `5 a% g5 N' ^ _
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
# t0 h/ M7 Y: p. U0 ?0 a5 _, U! ?5 C
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
$ G; i% P/ W& p. w0 }& N
* F; b* S# ~) C' I- o. S
2. public string[] Split(char[] separator, int count)
) T; ^- [; H0 H* f: c5 n2 Y( F
0 y8 q8 I4 W6 c/ i6 Z7 G- K
程序代码
; }; u. ^, z0 U8 A1 I9 ]
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
# D* ?5 e; j: z! K9 q# j+ h
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
B+ T- n8 a- S% U7 f X
8 r1 s* V4 U1 Y$ p
3. public string[] Split(char[] separator, StringSplitOptions options)
! J: k! `- }* X8 ?+ G" a
( m- @6 Q. k6 C1 P3 V: C
程序代码
) F ]4 g% V2 N8 Q# A$ ~1 v/ T
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
+ e4 x. [( O/ r3 J, K: h* t! u" O
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
& o0 z( `9 v8 J" n" t
: y( U/ x$ a: K) p0 Q' V, P2 T
4. public string[] Split(string[] separator, StringSplitOptions options)
* l% g0 j' ]0 h4 h- z3 M
8 c' r1 x Y3 F) @6 N
程序代码
# ~+ P! b* P8 C5 G
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
C' ^3 K2 _( R! Y7 M, J$ z% R
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
, ~4 d' ]" l5 D2 Y8 G \1 z1 o
9 C7 }) ?2 _* r0 B* U) _8 ~6 \3 r
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
) C3 l+ f7 z C# H4 s
# e0 j q. S2 c& N
程序代码
$ J6 C! t- ^+ [9 f
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
& d( {( L' z/ `: g; T1 j: ?
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
$ W. Q- l$ B8 Y/ ?( B f
7 N) V4 d8 a' T$ c$ H1 z
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
" T2 D/ }$ U" r, R6 h' T
$ B4 L9 u+ J; A
代码
! E6 s- P/ |; u) V% B2 M, ^4 S
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 ]% d. |. O3 Q/ N2 X7 Z
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
欢迎光临 晨鸟科技 (http://www.chenniao.com/cprofessor/)
Powered by Discuz! X3.2