晨鸟科技

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

作者: Star    时间: 2011-2-18 17:28
标题: 升级程序开发——读Web.config、执行Sql脚本
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
2 `3 V9 w( B: {( O2 S! j0 N/ v- e% u& M' T
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
7 S0 p! n8 ~2 t) m( z& q* ?" M6 j2 E. N: s
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
作者: Star    时间: 2011-2-18 17:33
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
; G4 a$ X# u7 [7 x) L1 t- u1 nhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
作者: Star    时间: 2011-2-18 17:37
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
( t8 z9 l% M3 a% }http://www.itwis.com/html/net/c/20100506/8234.html
/ K; t! I1 m) K. \* c
  V( k4 m* b9 R; I0 Y( `程序代码( \( v& O0 w$ P) t: f( u, V
1) public string[] Split(params char[] separator)
# P: r1 O7 v: R$ z. r; j- B, a2) public string[] Split(char[] separator, int count)
+ z3 x. d) P8 o( `$ U3) public string[] Split(char[] separator, StringSplitOptions options)/ a, G! b8 ]' h# `
4) public string[] Split(string[] separator, StringSplitOptions options). H; T/ q! I' x  m  n
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
5 {4 C4 l  I. U6 H4 J6) public string[] Split(string[] separator, int count, StringSplitOptions options); W7 u2 G4 Q; b/ S

- H. `* A! i, d& O3 m下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):# Z2 o* T9 e2 B" g, ]+ V+ d3 w
5 U. Y# R/ c$ B4 g* I  i
1. public string[] Split(params char[] separator)# M; ^3 y% o% N7 `3 p$ N
- {$ i! W& _6 N) N9 o7 O) j
程序代码6 i- w! k; u8 w- E* `6 d* }. T4 B
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
( p4 x4 ?5 ^; y, A; Y1 Wstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, V) I2 b% c3 W$ C& \/ G3 b' p- |" B
# F* ~' B0 w# {. Q. L2. public string[] Split(char[] separator, int count)
( k4 N7 p, N- T9 U& m2 l, t$ p3 P# d
) J) h% }4 Z# X& X( N 程序代码. K# z# i' Y1 P' |+ S
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}* t$ E- r9 ~" B+ j
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
( K% d8 m# n' z: {: K
$ h9 H- ^1 b+ z6 n5 J3. public string[] Split(char[] separator, StringSplitOptions options)6 l% g" r0 }5 q8 W7 r
$ `$ s6 _8 l3 k, g/ p
程序代码3 [& D9 d3 U2 C6 ?" Y
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! x" w8 _  N( E( l( Hstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) J  D: f1 M+ n- r* S* ]& e5 S+ d4 Z# F
4. public string[] Split(string[] separator, StringSplitOptions options); }9 s3 A5 @7 E

4 C; L& g6 n2 _. d 程序代码2 V" |: j# x  V# O! B
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' P3 v% R& g) P3 A
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 C9 z& V, f& J: ?* b. T' U
+ z4 W3 R. G) J4 A6 H5. public string[] Split(char[] separator, int count, StringSplitOptions options)' @* U' J2 R5 ~0 ]( ?

$ |) C" j$ R% |# t9 | 程序代码$ a  _7 p  C& E9 M7 n7 M
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' {9 e% K( v" v1 L8 f
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& c! d" U4 _0 \0 s1 A: o

% i% G; ]" B/ R$ v1 h: x% |6. public string[] Split(string[] separator, int count, StringSplitOptions options)
% |8 J' ]2 c8 c; ?. v) B, o: w0 B, j+ m$ W2 b7 T+ H2 B* M0 x& {
代码: h  H5 H+ n' ~: e+ ]) y* q; ^
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 M  X8 u" n; C- K
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素




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