晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
& Y, ?. |* L% s" f! m5 g8 S6 S& @! Q. F% u7 Q! u
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
$ v  F& z1 {" _9 Q% F6 w- ]& @5 Z( z- O) ^7 P; P4 h& P" r4 y+ b
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
; S( W4 D7 n1 lhttp://www.itwis.com/html/net/c/20100506/8234.html
+ D+ y# g, G& ~2 m- z' _6 [4 O& |6 ]6 ?( {, x' @
程序代码
6 k, `2 w$ l. G: ]4 W- U8 h9 _1) public string[] Split(params char[] separator)
/ Z) W. w- ^  u7 n4 B- G2) public string[] Split(char[] separator, int count)' d6 s* Q9 ?3 F$ v. N
3) public string[] Split(char[] separator, StringSplitOptions options)/ U; ]0 |4 S+ q' W
4) public string[] Split(string[] separator, StringSplitOptions options)8 f& C4 Q: G1 T9 [6 H' ^
5) public string[] Split(char[] separator, int count, StringSplitOptions options)' E5 q0 X+ K' |8 Y
6) public string[] Split(string[] separator, int count, StringSplitOptions options)" M# r; B- _1 c+ \  w" y
! P) E8 {2 d  Y  S1 S* b. f/ K
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):; w( M- q; U/ a2 Z: i3 k9 z
: \. [. U" f3 j8 W8 w
1. public string[] Split(params char[] separator)
+ }. B5 s! F2 ~' G) z6 b6 m! b& \* h& P6 x7 s+ y
程序代码  ]4 u8 ~, n& A# c) [
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 M& H$ P6 \* y$ u3 Y
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}: h, U1 C2 G" A6 o: y1 f& I

, e* }9 S' i6 V: v/ @. e2. public string[] Split(char[] separator, int count)
& x. n3 v6 s' R, J2 R9 l. J3 l; W4 K2 w$ t* h0 N
程序代码
) _9 P  }3 u4 x0 ^string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}+ j. V' L" K: L6 o
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
$ b/ [4 d% u: j+ z; U  I! o/ V( v) l& U
3. public string[] Split(char[] separator, StringSplitOptions options)
5 ~& ]6 G  f$ o8 r' g7 x% `4 u0 j1 j) `( l' H) A8 m
程序代码5 a1 e) W3 u5 _7 u! P3 d
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 {% q7 u5 w5 Q8 Qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' @$ R3 A5 N+ _: T

3 \$ X* Y9 m$ c- _4. public string[] Split(string[] separator, StringSplitOptions options)6 D1 s! H0 z4 d2 S1 v
5 ]+ Q0 y) Z3 }" ^( h+ Y, s6 i
程序代码6 {" d% n3 S- v: Z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素7 a; Q0 f4 o% F2 X- w
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 y6 K% d! ~2 h8 E
) r2 B1 t5 B& l  @9 r7 s4 a5 y
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
; m9 I" H0 \3 S: U
% {( G: U  r# K2 g) f/ y 程序代码
2 P" I7 a' \: p6 R" [string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: D5 Z1 {$ n  @string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 u8 L6 R7 S: l7 y/ l5 C
& J3 W2 |, W0 A0 n6. public string[] Split(string[] separator, int count, StringSplitOptions options), J$ M! A  x0 A* ^
7 h! g' v5 p2 ?: {
代码' f4 f# G3 U- E/ }0 m# F3 B, m. A
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素, _, L/ Z/ S" Z' H( I  X
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
8 i9 d% Z5 x! n4 p9 khttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-11 15:21 , Processed in 6.071877 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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