晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件6 N# c0 q6 R) i1 q
5 e9 g) h4 i2 v7 x/ }- g- j2 C. P0 F
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码( n' r1 s: ~% a( q* }7 ~; E! k7 ^4 E4 Y

- t% g- F, r. K# S5 y5 }# ^对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
6 Z2 t# d& [! {- }1 V3 Hhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看5 B4 M. G9 X" I; P) a% I
http://www.itwis.com/html/net/c/20100506/8234.html
; M; C. K2 ~8 o% x
; P+ t9 w! j: e+ e程序代码
/ |# K! U. M3 J( E) b1) public string[] Split(params char[] separator)  y& k; ~9 W1 e) t. C
2) public string[] Split(char[] separator, int count)! }3 u3 g; U. d$ ]. g8 r
3) public string[] Split(char[] separator, StringSplitOptions options): t; Z7 b" c. B3 r; ?- a, ]6 ~
4) public string[] Split(string[] separator, StringSplitOptions options)% p3 N3 s9 \6 k' w( D5 g/ H5 ?
5) public string[] Split(char[] separator, int count, StringSplitOptions options)9 y  g% C! \0 w. S9 v0 e6 T/ j
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
; F: }8 m- f, A" V0 ]6 b, I) j2 d5 {8 j, `8 ^) A, E. x
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, Y5 I; ]- J7 |. w+ Z. N' s. B$ j
0 a5 Z9 K5 W/ I( c, \
1. public string[] Split(params char[] separator)+ r% y' M. l3 c( p; ]2 O
; |, t% Y' r; }
程序代码
& h% J9 n6 X+ D9 d+ j4 m8 @string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}" w4 s) X0 A" t0 s6 T  U0 W7 z
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
6 _# O: w2 {0 \4 c; }* v0 c2 ~5 t# a! U. `/ X
2. public string[] Split(char[] separator, int count)" t% U: H( S( P% Q. w7 [" k9 g
) f" g& W: d! ?
程序代码0 `4 [) L* u  U; s3 ^, O, Z
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}) L% k7 X3 I, E" y
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}3 A$ {4 J* K( w
3 l3 r6 M  `9 L0 h( U1 @% t8 u
3. public string[] Split(char[] separator, StringSplitOptions options)( X: u4 g# f( ^. w; g2 ^

% F: i  V# Q) ^: Z 程序代码( Q. L- c, A; U% H1 i% [: h
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 ^. }2 `" }( e8 ^9 pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: N0 O6 |. R1 @7 g
$ ^; M' W* a- H* a! Z4 H
4. public string[] Split(string[] separator, StringSplitOptions options)6 {. a8 ~, z( L6 o9 S
( O0 d7 s+ \7 P: L2 q/ ^
程序代码6 {# Y8 W$ I% \- f  p( V
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ F# t/ _+ E( Y; Jstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 \, D; M2 c8 c0 P; B: K
1 z. I& ~( r: r; J, D) k' B9 r5 }
5. public string[] Split(char[] separator, int count, StringSplitOptions options); {+ o9 i3 V3 O) J1 p

1 h+ d! x: V) B" e' T: r 程序代码
: s5 \& x9 v9 z2 I: l) k6 Astring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 b7 U/ K0 N/ S" I1 }string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' T, q5 ~0 f) [% k8 E, Q; v+ C; ~$ C: }8 N* u) R6 |4 O
6. public string[] Split(string[] separator, int count, StringSplitOptions options)( d9 }9 U: D- i5 K+ S1 T

. O) u- W, f, w  v/ ]: C: z. V. Q/ x! n代码! j  z0 B& F' A/ V( o1 j# g* c, \/ q
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素6 ?  c: D! Q, T# x6 o8 p; S6 {
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-24 11:17 , Processed in 6.066639 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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