晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
6 G4 p3 {& X6 ^. P" V$ n' Z6 k
+ ^9 ~5 v1 A2 H0 ]* Z/ S* ~  S2 s读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
$ n+ o# d" y6 ]: p  u6 y2 m2 }( |1 P+ ?# c* W8 J
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
/ w/ ^5 V6 A5 a1 t: {% Dhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
; V$ V, w7 M1 X1 ~http://www.itwis.com/html/net/c/20100506/8234.html
* Z9 f% W0 H7 p1 s9 m2 N- D
) \4 |' w, u+ B9 J. n程序代码
) q) _" ?' C0 q+ G0 ^+ S: ~1) public string[] Split(params char[] separator)' `0 b1 M6 b  Y! i4 O
2) public string[] Split(char[] separator, int count)
3 E, t) ]& D4 e3) public string[] Split(char[] separator, StringSplitOptions options)" H$ V( A( ^2 j* D8 U* \
4) public string[] Split(string[] separator, StringSplitOptions options)) j/ l+ u3 O$ C2 r
5) public string[] Split(char[] separator, int count, StringSplitOptions options)$ W3 d5 H4 C* T
6) public string[] Split(string[] separator, int count, StringSplitOptions options)! J* ]6 g; y8 e

1 o( T* e0 {9 Q" J. C+ B4 b. Y2 X下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
$ }( W5 Z; T; h% P/ N# J; n7 g
7 q3 q/ Z; o  R1 A7 u7 H* F1. public string[] Split(params char[] separator): G$ E" A5 K4 w6 k" Y

. f* [0 m, X3 m! O! h 程序代码) r& n$ A3 O- z2 V4 Z. D) \2 W
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}( ~6 X" ]; s7 ]! [" R- G0 d3 B
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
& J5 p) M9 @! O, Z; _; _, Y1 s& ]( Z( |
2. public string[] Split(char[] separator, int count)% ^! N/ B; e+ v4 C7 I9 G2 l! r* c

1 w9 {! \3 C4 [/ Q8 `# W, h/ m 程序代码
7 G3 _3 r( Z/ u& e" a+ dstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
$ u- M0 h6 B3 R9 ^2 i8 r3 n) ]- }string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# H* {  x; Y5 }% Z
8 e- E9 s, I' {/ z* z5 V  W
3. public string[] Split(char[] separator, StringSplitOptions options)( k5 m2 Y' B& c# W
) m# l) L, h+ F0 J. [+ }
程序代码  d0 p( m6 f, w0 o. B8 m
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! B5 j$ f4 x# D7 G/ ~4 [: n) b
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# Q. i& z# e/ ^3 Z8 M3 o& F' D

1 ~# @: i6 A& Z6 S4. public string[] Split(string[] separator, StringSplitOptions options)
; \  @) X% X% L% p, T4 c; q# v! s, u8 Z( f5 m: U: H- I
程序代码
6 t: c  r9 S) Y% p$ H: a7 {2 }string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素6 |9 z/ a1 I. U! H4 C! c" t  S
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素( v. E! X  [5 ]# K

, p% S0 e, h! X  [" |5. public string[] Split(char[] separator, int count, StringSplitOptions options)
% I6 z7 O# E0 o& s3 K% I" d/ D% ~5 @0 W. Q* E2 o
程序代码/ t! ^  S% N$ f+ u# e* _- }
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素4 k4 V; C  y4 W; D1 L0 @
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 R: e% s* A1 p
7 |  [/ M. O- l& O2 ~5 v
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
) _- @% ?* @3 Y8 P3 u( t4 |; g: C. I9 F
代码; |/ G9 r' k; f3 x! V9 H
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: O( n- Q' _: g/ u, ~string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-3 05:20 , Processed in 6.066639 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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