晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件* P, f2 ?/ p1 H
9 i* ~# \. M+ ~8 K
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码: Y8 b, R' W) D! C2 N; D1 o) X

: I1 \2 w" v5 D1 Y( C/ @  }. p对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
3 i) w9 K' [6 N( j9 f/ shttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看( ]) w, \+ k0 S  s
http://www.itwis.com/html/net/c/20100506/8234.html* u+ I) U' i' e; F$ I3 ?
8 J2 R, ?' r4 I; M! q; C# ]2 r
程序代码
  g7 Q; ~2 x( `5 N, _: o1) public string[] Split(params char[] separator)3 d# t( B6 O, L0 ~$ O5 v
2) public string[] Split(char[] separator, int count): V2 u$ J  |! s) U; R9 a
3) public string[] Split(char[] separator, StringSplitOptions options)* \. m9 l" }! \9 U8 U7 C( ^
4) public string[] Split(string[] separator, StringSplitOptions options)
: m- x  [% m. j- ~5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& I, D7 r$ l. R6) public string[] Split(string[] separator, int count, StringSplitOptions options)" F$ g( Y& j# y/ ]1 @
7 q" v# ~6 ^% s4 O* J
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):( N; t% m- S0 e8 _# A

9 v# r" N& M  P/ Q; z6 E0 O* a* ?1. public string[] Split(params char[] separator)
: Z* c. C0 r' }' Z3 i
: q) b) s5 V& F2 ^ 程序代码, K/ u7 z8 W" T, n& L
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
; h' z+ W# \$ J( ^+ H/ Ostring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
( p0 ?- B) O1 @2 K, o3 p0 i& {
5 H, m/ z9 b4 R( c+ q+ H& f" d2. public string[] Split(char[] separator, int count)$ s, w# M7 i. U# ]% n6 o+ y$ Y( O- B

& X( N7 T! q0 P4 q6 x8 m 程序代码$ S( I3 i4 {5 I  }8 e
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
$ W* s1 E# X' B  R' D, m! ustring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}5 T& L& F* b; R  e

" r) _* C5 l; T6 o! a3 j" v, I3. public string[] Split(char[] separator, StringSplitOptions options)
. {2 T: ]$ }3 \$ o! R$ o8 r( b( ?" o' g3 ^0 d6 c* p" Y% y6 B! u
程序代码3 ?( t# f7 m/ s& T: ~
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
- ~/ i. V! t' y/ |& sstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
" o* N7 O: k' U, e
9 m/ k* v) e- i' H2 `2 x4. public string[] Split(string[] separator, StringSplitOptions options)
8 H( w' H  @9 k% p/ J* n! {5 B
7 x5 C' u. F3 t3 q 程序代码
! {" t" `* n0 w9 R  V/ ustring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 e0 G9 |1 u1 Z2 X9 X! w2 A0 e
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
# ?" q+ v9 b$ F4 u% |* P/ D8 ]( J: G9 L8 b
5. public string[] Split(char[] separator, int count, StringSplitOptions options)4 g; J' n5 w3 t) v# D, c7 ^1 ^4 n

1 Q4 T/ `) G# C1 q- q* L 程序代码& `+ F5 Z& o/ r/ t0 C* G( h- a' n
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 \$ \- X) r! m3 ?% Gstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 n( {! I; |. z# F

# U. Z$ P! K  v) [* j2 [  I* t6. public string[] Split(string[] separator, int count, StringSplitOptions options)+ r1 q8 a- R: ~7 J0 C
4 i. D* L, ?+ x7 _) a
代码2 K: l( x5 ~5 W
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素- \) M6 h& m) {
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-9 10:28 , Processed in 6.085548 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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