晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件; \2 ^8 b1 w4 [( M
& k8 p7 z0 N+ y, N
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码: Z9 E8 a$ I2 A" o4 }: T
  o( T6 `" Y; a: H. B
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别- j7 i3 W7 }0 h/ ]5 z! v5 \
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
" _: Z! }' ?# Y: ~4 Fhttp://www.itwis.com/html/net/c/20100506/8234.html
7 [- A( |' O) ~4 B& s% P+ Z& p  D# c* t
程序代码
7 O2 r( o& E7 k; H. [9 K4 n$ G5 C1) public string[] Split(params char[] separator)  X' |  E% v3 Z& O" v- |
2) public string[] Split(char[] separator, int count)
8 O' Q# F% I; s# [3) public string[] Split(char[] separator, StringSplitOptions options)# C5 F7 D3 @# X% F- J9 f
4) public string[] Split(string[] separator, StringSplitOptions options)
8 i: Y% ?* ]6 X1 ~- O3 s5) public string[] Split(char[] separator, int count, StringSplitOptions options)
. b8 i: H: t, l! c3 `9 E6) public string[] Split(string[] separator, int count, StringSplitOptions options)0 P) \2 \- }+ Q

% f0 h2 S4 x! u/ a- P+ v3 k( o下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
9 F$ M# S1 B$ F- `" X
& Y/ t& \5 Z3 W7 F: j1. public string[] Split(params char[] separator)
" V- @2 J4 x' N8 h/ L5 i0 I& |1 G% q! \/ R3 e/ b
程序代码
: s( \9 k$ O- s3 ?string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}7 u8 w0 e( T4 g: o
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}1 t+ P, Y; X2 [3 @+ R* R% A
0 h' o$ Z2 y+ H, y; L
2. public string[] Split(char[] separator, int count). k0 x# A! j4 q3 `

/ [5 i) I& |, O- B* M8 C  R 程序代码6 O6 e3 f" l% _* }1 w6 L
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
- i, u+ C" M' G& Ustring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}( g5 a5 n, e7 a: e7 Y

' z% ]3 }' e% a! v- U0 i3. public string[] Split(char[] separator, StringSplitOptions options)
5 v6 R9 s# J7 m' V& T7 h+ I5 ?/ C8 I, s6 A7 W
程序代码) f: r, i5 Z' c2 \* Y
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
4 }0 c8 p5 \' Y, i* x" ~4 V8 estring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% i; ]  I+ v9 S: H
2 u1 s7 F8 i, @; G$ m9 J. E4. public string[] Split(string[] separator, StringSplitOptions options)
( h; S. E/ P. B9 c& |" f2 Y# @7 y! ~( h" H7 S# {3 x: q
程序代码: L. b1 j* ]* a: z2 m5 O+ b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
% ?: v6 m- i, sstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素( E! T! v$ m9 [6 A$ r, k

  u$ r3 i, W& ~8 ]. s( m5. public string[] Split(char[] separator, int count, StringSplitOptions options)
9 d8 W  j3 K" {' d3 v( J
: h8 J7 l3 k7 ?  Q; ~ 程序代码" Z3 O+ ]% i5 |( k+ [9 Y. C
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
5 }, O  \8 B/ U; E/ x3 P( t3 H) X3 Astring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素* W6 {5 N7 D, K- U& I$ W
5 Z/ Y8 v9 o& n$ y% k
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
3 Y+ u2 F! f9 b: b" g7 [& C/ Q, S1 q  ]( U' M
代码0 ]: P& m2 y, ]: m2 Z
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! }. z; I  X$ e" v& Q
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-25 08:00 , Processed in 6.066018 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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