晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
" s0 ~7 _! T" z: }
9 l. _$ Y' y6 @2 c0 T1 H8 x6 z. ^读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码9 M: z7 z, B) h" p! D# p: u- H
) L* o) U( \! k* ^4 H; Y% `% D. C
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别0 {% f- W, n: f: L( e( m; ?
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看7 P8 n. {7 V+ q  k
http://www.itwis.com/html/net/c/20100506/8234.html
2 R0 _$ Z. Q4 G& B1 w- b5 c- U7 V" D8 l3 B# j) o( F& ?
程序代码
$ Q" p' O0 ]0 \4 T4 n1) public string[] Split(params char[] separator)& E. I- W( D! B* X
2) public string[] Split(char[] separator, int count)
, F/ O( ]7 o; H9 q1 y$ x( b3) public string[] Split(char[] separator, StringSplitOptions options)
3 e/ V) G- m3 h" y. T4) public string[] Split(string[] separator, StringSplitOptions options)9 |( F7 W1 S4 ~, i) `5 Z/ a1 l
5) public string[] Split(char[] separator, int count, StringSplitOptions options)5 m+ z; X/ l8 v  D
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
. X1 n# M' c) H) M
7 |; O" q+ O! ?0 c下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
+ U- F/ U2 p6 o, P  I! C; _/ s
: S; _6 Y9 f, K+ T: Z* e! ~1. public string[] Split(params char[] separator)
- ?1 l) u' W7 h' t( [/ H
0 s0 T3 k2 ^# F; z 程序代码4 q; l* {6 c3 Y8 r. f2 _, |/ v
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}' b7 d) e4 M5 G0 q- T, S, B
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}2 d# }7 O& C* Y1 ?6 ^5 q! S

# u  Y+ g0 t- P" v; P2. public string[] Split(char[] separator, int count)
3 I; u9 J! h% j$ i6 a" g+ {* M1 a) _& c# o9 v5 y0 i
程序代码
4 K: n9 q: U# i4 Pstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}0 u; K6 y$ s0 E5 U# h( }, K& R; b
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
- O# ]( e4 I7 u" D, f6 Q, l# g8 @& b5 O
3. public string[] Split(char[] separator, StringSplitOptions options)9 Q- L, {4 |! I8 v
& O& \! v' E% v3 H+ k) P
程序代码
* ]1 z- N' ]: g; w# g2 L2 rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
0 b2 n/ g. V- N8 R# `string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 C( m8 n9 P& u! m
/ t& z# J5 ~) @- W, I
4. public string[] Split(string[] separator, StringSplitOptions options)
2 i+ u3 _5 ]/ j% q  s
) F$ W9 ~( F6 A* b* g 程序代码) V& h/ r% L# \# S
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! V- X! d$ J+ O  w0 h2 S3 r
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 A4 [& k& w3 f3 P5 D" w
, n/ C5 y( B4 m( q' b* k/ B" X
5. public string[] Split(char[] separator, int count, StringSplitOptions options)! V7 J, r2 l' V9 n( T" y2 n* Q/ p
. c' q. f9 d9 \2 u- B
程序代码
- S) L+ k9 G1 K$ [1 z! Nstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 W6 X6 P5 ?+ i0 Vstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 x1 p4 I& u8 i) D
6 \, ~+ u5 Q, [6. public string[] Split(string[] separator, int count, StringSplitOptions options)
. [9 p# q) E2 {0 u( x& o! Z
$ ?' t3 A5 M7 K! ~/ c代码
0 n6 `% t+ Z2 ~$ k0 n' m( Kstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
1 \/ v; r: b* s8 pstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-4 18:11 , Processed in 6.072854 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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