晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件: ^& k2 t, k/ q1 [0 V

0 J3 m/ L. }4 [* d: ]& I& S读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
9 N: m) S5 a# M9 D/ H8 K; k- Q$ P' v2 f. d3 i2 U6 C6 O
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
8 ~6 \! T: j" ?( @http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看& z+ z0 `$ G9 `- D* z9 }- G
http://www.itwis.com/html/net/c/20100506/8234.html
* v9 R" E# |- |/ H$ j( r: V! o/ J* F$ m# f# V* q
程序代码
+ l  M' I0 q1 B! F7 y; p5 y8 {1) public string[] Split(params char[] separator)
: l' j9 N/ f1 u, M2) public string[] Split(char[] separator, int count)
1 t+ ]% ^' m8 n3) public string[] Split(char[] separator, StringSplitOptions options)
, w& ]6 r6 S2 L  q8 h4) public string[] Split(string[] separator, StringSplitOptions options)
& _2 R' a! q% U2 F  O. J5) public string[] Split(char[] separator, int count, StringSplitOptions options)
' e1 i" L: L  U. D. ^6) public string[] Split(string[] separator, int count, StringSplitOptions options)4 O% x8 S1 j$ i! k6 a

* n: ], [# @/ Y/ a下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, m1 Y5 }3 F; C6 r% P
, F* _7 w- q, Z' M( |
1. public string[] Split(params char[] separator)
) H# M* h9 `7 V5 P) H2 R' s
: E* s9 E- N. N% g0 f 程序代码
4 V" t# J' }8 z, Hstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
9 [' |1 Q* F& X1 |string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}' i. b7 {9 Y" h

2 u7 I; ^) ~" E- S& `# {2. public string[] Split(char[] separator, int count): s& ~+ i4 N5 U9 |
3 S+ W5 c- W: Q" F( `9 i8 V1 L" o
程序代码8 H! G6 V+ p1 g/ ]; J# h. p
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}* H9 T  S9 k5 `( G/ [5 T
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
; t2 {0 m: d& Y( @
7 g1 K, p2 @) z( u1 H3. public string[] Split(char[] separator, StringSplitOptions options)0 X1 Q0 S" K$ x/ U& `

. D9 W3 A+ c7 e9 q) r) i 程序代码7 `' ~* o# K/ W/ A
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素& m* b% m) F% e6 @
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素9 o" }& B5 \% a# }

. H7 v" `0 {3 _4. public string[] Split(string[] separator, StringSplitOptions options)
! a* A9 m! N8 l2 P+ `/ F% Q: p! p0 W' Y2 v' M' R& ^# T
程序代码
  Z1 F0 m: w7 n! e0 j* j+ ~( Xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! L$ S% r5 W) U5 m5 a3 y1 o- i
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5 ]& l; D* d- \& t( ^4 G/ w0 W$ G. O' w1 a# v. Z
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
3 ~6 s. w+ R: R3 B3 f1 |, O5 b; y: b( P, ]+ }
程序代码
  n+ u' M" N/ c" h5 _; C: C3 U: Ustring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素9 n0 O- |1 ~% \
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 X% V2 {0 r* Q6 o7 l$ y/ E
. ~( g8 `1 n  {' ~/ B5 Z) x
6. public string[] Split(string[] separator, int count, StringSplitOptions options); `8 x* L7 f9 h. P. [$ b( u

5 w3 S' D9 d& }' B1 r代码
5 D; E1 T" c* C8 L& G7 f- Ostring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素# ?3 G* p6 d# _, d( c: f, j
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-7 10:27 , Processed in 6.066018 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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