晨鸟科技

 找回密码
 注册
搜索
查看: 13261|回复: 3
打印 上一主题 下一主题

升级程序开发——读Web.config、执行Sql脚本

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件6 p! |  g# {! y' R/ j
' {8 B  }& {2 @6 V6 l
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码- r) A- z) M; K" b
4 s& U( M" V: J7 i% Q* f9 A
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别' Y5 c! l8 l; h. E* R
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看) j! D: e. t$ M" a9 d" g
http://www.itwis.com/html/net/c/20100506/8234.html: A( J7 Y6 R7 O- g9 d  p

( P) s9 B; |9 `4 g/ S1 f) t程序代码  x6 E5 ]7 K& U2 n% O
1) public string[] Split(params char[] separator)
7 s0 ?" y: i- n' N: s, p3 P$ @2) public string[] Split(char[] separator, int count)* N; o1 P7 |% _% w7 E: B$ A
3) public string[] Split(char[] separator, StringSplitOptions options)
( A! Z9 r) S& i2 n9 `+ A4) public string[] Split(string[] separator, StringSplitOptions options)
) ]! A4 H5 {$ f$ Q& h  f5 Z5 z) i6 D5) public string[] Split(char[] separator, int count, StringSplitOptions options)* }& U" j- X8 w3 {
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
; C8 ?. k/ G8 w' ~  R, {, o% C* f8 h* F' p0 X/ W4 R. [9 e: Y7 p
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
9 t" W( Y; a6 M$ w4 C9 k  U+ E- P& u3 \9 Z
1. public string[] Split(params char[] separator): j8 ]) ]" I( o

) ?2 e+ d( }" R7 d3 T 程序代码
( W- h, x+ l/ Qstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
& D6 X  K7 V0 X  K- t1 I$ Cstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}) o% O2 \# P0 u3 N# w

; b( `' J3 ?/ O$ P: N2. public string[] Split(char[] separator, int count)
* U, t# o- z2 p- W; \, c- Z7 K* n/ a% s$ ^
程序代码
2 l- t5 M; C1 H$ B: N) d, U4 X% Pstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}! k# i$ \6 m" w8 _! x7 p
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
4 `- x5 p" ?( t2 ]% G0 l1 O1 j( s$ s& p
3. public string[] Split(char[] separator, StringSplitOptions options)
. J4 b1 y( ]: V$ R9 h, F# d/ K  F2 f" T
程序代码
7 Z; \! V& B6 \$ `' y% r4 n" cstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 }% s8 `) y2 Jstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 C8 V6 }$ ^, X- `8 X9 \5 {1 |  t$ }; W: z" A: ?; f0 D
4. public string[] Split(string[] separator, StringSplitOptions options)% h+ A; y* j; O8 H2 d
# X4 x9 l, ^. S, {2 p& [$ e
程序代码9 G6 C2 Q# B$ e- `9 s
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  t8 |8 A$ P7 `5 K2 s3 ?4 sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素* f3 n7 G, B3 r8 R- Q

0 v3 ?! `0 k: b, E" v5. public string[] Split(char[] separator, int count, StringSplitOptions options)6 I" l+ s4 `: i1 ^" A2 }8 Q$ L

, p8 o- B' ]* N* B* O: e 程序代码9 Z8 G# g% U2 p( [8 Z$ O7 Y+ g
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素. j, |" v* T- o1 v
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 c: ]3 `. v, G4 K7 M# L# G% ?9 z4 T
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
" G/ h( b+ f+ c4 _+ Z5 {
" j' u7 P) H3 G9 ]代码3 |0 E, e) W0 a. }( N/ H  P
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! O" P& G5 |- r( F2 ]string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|晨鸟科技 ( 沪ICP备09012675号 )

GMT+8, 2025-11-27 18:55 , Processed in 6.063088 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表