晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
, ]2 L7 I2 K$ _9 d; G. [/ q
, M$ q4 O4 z5 l  Z. T读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
7 y; L, s% P2 e
% I+ r/ H0 r- k6 ]* Q对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( C9 J9 c( h! nhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看# o5 C3 |. z; R# A
http://www.itwis.com/html/net/c/20100506/8234.html
6 @! `  g3 J+ q8 ?7 H- Y+ O3 r9 \. w) Q/ e+ O: S
程序代码# j6 ^5 b" O1 m# i
1) public string[] Split(params char[] separator)8 h; G' G2 y/ k( }
2) public string[] Split(char[] separator, int count)7 ~/ u; m# Y" ~6 _# f
3) public string[] Split(char[] separator, StringSplitOptions options)
4 |2 V! F9 L2 B/ R# G5 r4) public string[] Split(string[] separator, StringSplitOptions options)9 N. x5 N' G/ z# U1 s7 s
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ c" ~9 y4 n. a5 I- T6) public string[] Split(string[] separator, int count, StringSplitOptions options)
2 K; f# N$ A1 Y! N& f$ M4 H
1 n0 }9 z. d$ ]3 l, I下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
$ n" S4 b* X( q: _: P5 Z
9 G/ V9 a6 i8 ?" ^  t) p1. public string[] Split(params char[] separator)
$ Z; w5 Z, A9 ^! N/ e' [7 Q* ?+ S6 |+ y8 ~# ]8 r, @
程序代码
. i2 J3 k' N" B: pstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
- \8 a9 q5 }. j) H$ Sstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
4 F- e) l) x; {/ P. ^
+ n9 j& A& i  O8 T2. public string[] Split(char[] separator, int count)
- ^% u4 x4 m3 E/ o0 ~9 j( q/ D/ h! j1 D' V5 Q6 P" Q. A
程序代码/ k' H5 j8 Z; q, z
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
3 g+ B  I+ ^6 n9 B/ Cstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}7 Y( i# m$ U$ U8 R( H
( U8 {: s3 q2 }; b
3. public string[] Split(char[] separator, StringSplitOptions options)
( f) y% M" Q( Y8 B4 Y3 P$ T  O4 E. a# W1 a" Z  c) ]) h( N, ^
程序代码0 k, c+ ^. M9 d0 X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素& K$ M8 O* b7 M- ^2 J5 S; w
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% c$ v/ s, z; |
# }, J# d; z2 w8 L4. public string[] Split(string[] separator, StringSplitOptions options)3 m6 D: d/ F; ?# a  ~8 A& F" p

7 f  V9 L  S7 z3 _- z9 w 程序代码# E/ A8 e9 Q/ M
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素0 t! |3 M! P8 ]
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! d" s5 G2 o% M4 D
& X0 \/ m0 |- q! E
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
/ I. c+ C$ D% r9 {: t6 v8 P1 I* j% v' n. J2 m6 R( M8 p* n% |* ~5 U
程序代码
" g8 b$ E1 k% Sstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
# }1 v* m. \: \8 S6 astring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" u0 t) O) k' z. r( t+ G

9 ]1 J2 A  {" u0 l6. public string[] Split(string[] separator, int count, StringSplitOptions options)$ G- ^+ u$ v+ i0 q# O9 z
+ {" D3 e& t9 z  h' n
代码; g4 M+ \3 X% y! [. s; L
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素7 J( n5 l' t5 ~' I: Z
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-1 14:31 , Processed in 6.064686 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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