晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
' S( ^3 n# z  p$ S+ i7 h& M
. C5 {/ U. w' G( y. Q读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
% M( U6 {/ y& U9 g5 w1 ]9 N5 z
4 p! K# Q; {1 N: F+ @对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
; s5 j6 e: m7 u. r! yhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看+ e9 c+ [' D. w& ]+ e1 d8 E
http://www.itwis.com/html/net/c/20100506/8234.html6 A: P0 x% h, x& G% s8 u* T/ a
$ m2 Y5 x3 _; T( r* y4 l" @$ l/ |( `2 N
程序代码0 d: V! B; g: \  g
1) public string[] Split(params char[] separator)) q5 m( k0 y5 g1 \4 H
2) public string[] Split(char[] separator, int count)( K* @. b# f: X, Y
3) public string[] Split(char[] separator, StringSplitOptions options)
5 e% X1 [0 i9 `2 |9 u4) public string[] Split(string[] separator, StringSplitOptions options)
/ s2 v" Y/ }, y5) public string[] Split(char[] separator, int count, StringSplitOptions options)
( G$ I* D: a- X; ]6) public string[] Split(string[] separator, int count, StringSplitOptions options)
3 l# ~, ]7 m% P! p  o) E) |
, x& q, Q& w4 c. B. y7 ?下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
) M, D- V& q2 R" R8 l: m. m7 a) ~& X: S  y: S! f5 c
1. public string[] Split(params char[] separator)
% `/ M  w9 r  H! ]2 w6 s1 ^0 V6 \. e# |/ I, _/ C4 j, m
程序代码0 u+ d, K7 N+ x
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
' i* w. s- @/ N, R& dstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}% C: t+ M: C( o9 M: J0 }. z
( u7 q3 D; Y' j
2. public string[] Split(char[] separator, int count)
( M4 m) J1 U$ A+ V
9 c2 t1 D. M/ W 程序代码' r$ g/ J; M* y. D$ t
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}6 I, ~. D1 O1 a+ V* c1 e& n
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# f' b' H' p* I9 F+ N9 P% f0 o
7 y& l# R4 y9 F( e% }
3. public string[] Split(char[] separator, StringSplitOptions options)7 m! l9 t# ]. D9 ~8 v) H$ b

4 D) O% _( F! @" A+ a 程序代码
" B, j) O2 q! Astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 x' V# z- V" D% Rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 ]2 ?: z; M& b6 H0 f  ]( }3 s$ B) y1 L& T0 Z- P) o
4. public string[] Split(string[] separator, StringSplitOptions options)
) u+ x: ^, g9 E5 s
& z. _! y) Q* Q6 T8 x 程序代码
1 c( G: P+ ~. B- w# }string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# L: Y" @7 T9 ^/ {  q
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素$ A! U2 B9 }. Y2 V$ r
7 i  V1 i8 R8 q& y/ r
5. public string[] Split(char[] separator, int count, StringSplitOptions options)9 x4 V) [: z9 {* `; h, t& Z+ W
' v7 `) R' \, s' k5 N: y
程序代码
; q) k& n! c5 k7 f9 N( estring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素$ |2 V8 p& P" @
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素$ p9 e' f' q& ~+ f: w# p
# U7 l% x+ u+ H6 ]  L
6. public string[] Split(string[] separator, int count, StringSplitOptions options)7 G5 {: V; l7 F' Q
$ W8 l9 o- G4 k: ?% v
代码
8 F2 c- B, Z4 }6 N- Gstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( o% m7 S- f) A+ ]6 W" }string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-28 12:41 , Processed in 5.443988 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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