晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
4 a  ]& K* j/ _' U: A
: D% c! c2 ]9 G6 H4 s读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
: O+ ^$ d4 h# q* o7 V- N6 P( j
/ G' Y* }$ s) |7 u- {6 V: D5 [6 a对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别7 w6 h- i/ s- o5 M
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看# G2 F4 H& s$ h4 D, I
http://www.itwis.com/html/net/c/20100506/8234.html/ ?+ S' X1 u" `# L: @+ V

- I2 c: z7 x4 }+ U4 Z程序代码
5 h$ X! e2 t; H2 p1) public string[] Split(params char[] separator)
% Z. h2 o, h* m9 c2) public string[] Split(char[] separator, int count)
% i" f( O3 f, x& V( n$ z* c3) public string[] Split(char[] separator, StringSplitOptions options)
3 i6 ?1 b2 x2 `6 Q/ E4) public string[] Split(string[] separator, StringSplitOptions options)
$ R3 ?' m4 v" W' s* a5) public string[] Split(char[] separator, int count, StringSplitOptions options)
# H9 p4 }: e) A2 E# D6) public string[] Split(string[] separator, int count, StringSplitOptions options)" D7 f) u1 T5 L0 W: D) I6 ?
- }. |$ Y, ?( F0 f( ~0 V
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):8 V0 I; L: q" k: ^8 G0 d
: _: {% M( W: _  @: J& t
1. public string[] Split(params char[] separator)  Y9 [" O6 Y2 W9 x0 `

  n5 [: `' [, w4 q7 k7 r/ o1 R# ? 程序代码$ {' D; }& P" g
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
% c6 \+ d1 [! Ostring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}+ s, R/ i+ v: _& j) A; E
. [0 U4 r  N, i9 c8 w/ i
2. public string[] Split(char[] separator, int count)
! N5 x4 W, ?: K% a$ R+ _' v& h% Q# W8 j4 H4 Z
程序代码
' `. b" L, a9 I# N' m9 e( astring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
% I+ q& ^, ^4 V& a+ Y) S: _string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
* ?( D, A8 G$ L& C  j0 D: V5 V! j) e" g% c- [7 I
3. public string[] Split(char[] separator, StringSplitOptions options)
4 \; P1 Q' ?2 T8 k. G
' n9 b' Q- X  a% M9 x 程序代码% J* D+ v5 B3 `3 r* Z4 w
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, n3 S4 P  X/ j# Z$ l# z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) o. G9 b* i% L+ F: L
2 l6 \" G8 ~1 @& H
4. public string[] Split(string[] separator, StringSplitOptions options)
5 ?0 N, ~# e/ ?9 y; k. X2 p5 |
6 ^4 e! B) N) o6 J 程序代码
+ r$ s, P1 `2 e1 c6 b# q; xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素$ p* z6 o2 R+ C  c7 |8 j: o3 ~
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, {, C4 C. q3 @2 z9 A
: i3 e! `! B5 ~* D- M
5. public string[] Split(char[] separator, int count, StringSplitOptions options)) s; e! d+ H% h

5 a# C0 |- p, `; c% z3 V* @ 程序代码
7 F, P7 Z3 [: B% O3 istring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素# Y/ s) B  z% e4 @0 O
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" B$ I" F  ?9 ~+ v

3 n* m6 O' r& V6 Y- {6. public string[] Split(string[] separator, int count, StringSplitOptions options)
+ u0 v! B4 P6 C. ]
9 F, s" u: K3 E; }4 t% V# ?代码
0 {4 J  E9 e2 k7 B( E8 dstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
; f. l! n! d: ?6 H- T. p) gstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-28 14:05 , Processed in 6.065042 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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