晨鸟科技

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

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

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

- {) i! |1 K1 Q+ p( [读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码9 W8 F5 i) E, c/ O: i- n

' d; o6 a' k8 x& U% k) l$ q! i/ o5 g对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
+ i5 I) c% y6 \0 I  }! q6 Rhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
0 @  U$ g" U. y6 k, Jhttp://www.itwis.com/html/net/c/20100506/8234.html
6 O: M$ E- k4 Y. a: I5 A9 X2 c) a* l# T0 ?' d9 g& o" i- b, O( l
程序代码5 [& J  M' G) w0 |
1) public string[] Split(params char[] separator)
8 `4 o& S! [5 b2) public string[] Split(char[] separator, int count)
% i# ~4 a4 z; o" P& U3 M3) public string[] Split(char[] separator, StringSplitOptions options)  D: S& W* C/ C! B
4) public string[] Split(string[] separator, StringSplitOptions options)5 f9 w: N8 l1 o; M$ X- }% ~  K
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; k) R: I% K! o6 d0 Q7 u# T6) public string[] Split(string[] separator, int count, StringSplitOptions options)
0 }( Q9 }1 P' U4 U+ o. u, r6 D! \" a2 G9 k0 _. s
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* z- y6 @7 W- {; k
9 F, b5 J/ h, p9 c7 x3 o8 T0 r: a
1. public string[] Split(params char[] separator)' l! C1 |7 a' q' g" O3 a
( r$ Q- p+ u, ~$ n5 j; U0 K$ O
程序代码
  k1 {& v. }3 astring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}, _4 E% l' w( W. r
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
6 }" y9 k! k6 y% f$ P% z+ y  ^, u/ Y& F/ c  O7 B# @
2. public string[] Split(char[] separator, int count)9 [1 j" A8 `; A3 F
2 }+ R1 T; s+ v+ R0 b
程序代码% q& O5 D( Q; P
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
! Z- n0 C5 G5 g& Estring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
1 O; T' x0 S: Z9 y, n' N
  T6 r/ c  ?# {, X3. public string[] Split(char[] separator, StringSplitOptions options)
8 F9 L& B: T5 v+ a  H3 ?3 Z
/ t+ ?( y4 v; j+ c/ K2 \ 程序代码0 U5 a! I6 [  C$ Q7 L
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# ~3 ~& A' x8 K- Y; \
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 s2 z: T8 @3 _) G  ]
; b: i$ u" w8 j5 g
4. public string[] Split(string[] separator, StringSplitOptions options)
+ E- ?& D9 c4 \8 m' Y6 x, c0 w& p! |6 R) {3 o3 V8 \
程序代码
* X* g' o! |4 @0 K, B7 S' estring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素& x7 D- a# L* U: d6 |. r
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素. C! d) J) u1 j6 y! M5 \

+ p$ x9 {& M$ N$ j& d4 r5. public string[] Split(char[] separator, int count, StringSplitOptions options)  m8 \; b& C$ p8 x; l$ W$ |& B
+ k6 o/ K' v3 p) G3 w1 x. @$ p7 w
程序代码
3 y% l  h6 o0 N  ^9 ~4 Dstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# I; @9 d, t; ^9 V) G. B4 A/ w1 ?string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5 r; s+ \$ F- D5 N7 s. M8 g" W6 U8 Y% i' p; F
6. public string[] Split(string[] separator, int count, StringSplitOptions options)0 O6 I( d. t4 O2 q! w

& ^( z! `$ e( e代码, {- T7 z* `" D, W. ]% _1 A4 o
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( k2 a9 H" @5 c" C
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-7 06:11 , Processed in 6.067971 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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