晨鸟科技

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

作者: Star    时间: 2011-2-18 17:28
标题: 升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. I1 ?9 {0 ]% s6 Y6 j
: `3 p* j" U! _6 O* a' y6 P# W( ?读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
0 x& M; A& e, S6 I
  `; r- T$ V* A9 t, `对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者: Star    时间: 2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别, w: g& b; r! W) [
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者: Star    时间: 2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看" e, x$ q; L, f! |
http://www.itwis.com/html/net/c/20100506/8234.html
, i) |' z7 d  Z6 O+ u$ e
$ d7 ~9 M# U9 v: p9 y: T% g程序代码
( W! i. A$ V$ l% W* W1) public string[] Split(params char[] separator)% g$ l2 w! _  Q  C
2) public string[] Split(char[] separator, int count)
' C- A9 N2 s6 F* u3) public string[] Split(char[] separator, StringSplitOptions options)
% ]" @' D+ i( w/ E) O- \3 `, J4) public string[] Split(string[] separator, StringSplitOptions options)0 G$ E. ~+ ^8 }) i
5) public string[] Split(char[] separator, int count, StringSplitOptions options)  H- K& M8 F+ b
6) public string[] Split(string[] separator, int count, StringSplitOptions options)9 c4 V) \$ N# s% C. D3 K* D
( |8 m* }/ j' s) |5 }9 A9 e( h
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
" g' y  E' o+ A6 o9 C* @2 T5 E5 z, X, b2 T9 X
1. public string[] Split(params char[] separator)
; R, }6 j& I6 R2 k! {* [( o, j! @0 V
程序代码. J9 c) X% Q3 {
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
. L1 I4 w# v/ @string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
  l1 Z$ ~) K: K3 V; {3 m% u  p4 U! g8 K1 P
2. public string[] Split(char[] separator, int count)& t  g- h# P- ~# P

' R* S. ~/ P2 p 程序代码
" ~: x$ Y8 x& W) @9 \9 X2 f% estring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
) u2 Q' L) z) R+ p6 H! vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}/ T# `2 J2 J% S* W" q; |
6 q/ d: s; z! l, |; _
3. public string[] Split(char[] separator, StringSplitOptions options)' z; U% N$ u6 @% Z; v1 C
0 d+ w3 \) N# t
程序代码
5 j+ ^' ~' W8 `. F2 bstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
' t$ W& a2 X$ q: S! T6 astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) U* [/ {$ x( O/ N$ ]2 W- u3 q- f
$ [% l6 x# G- O* T/ A4. public string[] Split(string[] separator, StringSplitOptions options)3 t* l) K$ w/ `
( q) u9 ]8 q. b( C2 r2 _1 Z
程序代码9 E" U8 p: Y6 ^- H0 z& J
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素: N4 R4 ^: Q0 G2 H/ n6 ?
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
# u: `& K" H& ?$ t, o/ w9 H2 E; W$ x+ s' K
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
/ a* a# c8 J& Y/ I- {( d0 D  A, l$ G
程序代码
% _8 |' s  C6 M0 ], J6 F! ?# o. e+ Jstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 M2 `+ G7 B+ F, d/ h
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 l6 a, C7 d. ^. L! ~4 w/ \1 k
( x' j1 _# e( Y/ {& G& S9 y
6. public string[] Split(string[] separator, int count, StringSplitOptions options)& t9 I$ Y5 d; p. o
# q( I2 |  w' w' {5 H
代码' b2 m; q/ l6 I" ?% u# C! A0 H2 I
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 @8 \: J, K4 A3 k: kstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素




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