晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件; ]8 d% a/ Z, i0 e9 m. T) x
- Z4 q* ~- U$ O9 m
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
1 p5 y" l6 [& q" {2 G# {( L$ f* s$ b9 q7 j9 V
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别: o! G0 `* w8 g2 G2 K  E
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看0 ?+ A% W. p8 b2 E
http://www.itwis.com/html/net/c/20100506/8234.html$ ~! s0 Z" e, W+ Y+ F' K
+ \/ A! u: e. B9 m1 q5 q' H3 d
程序代码8 Q$ a% U3 j" e5 J) O3 y: C
1) public string[] Split(params char[] separator)
; Q# a3 V8 i; g9 g, W1 |6 W& a2) public string[] Split(char[] separator, int count)/ ]1 N' D5 U+ X
3) public string[] Split(char[] separator, StringSplitOptions options)8 ?: Y0 h6 f4 g
4) public string[] Split(string[] separator, StringSplitOptions options)
4 T) ^3 f7 e$ o1 T6 G, e5) public string[] Split(char[] separator, int count, StringSplitOptions options)
- c8 a7 H+ {  B' l! D6) public string[] Split(string[] separator, int count, StringSplitOptions options)
* n  Y+ q8 A% u: F* ?
4 I) k7 s& Q% u/ u下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):8 n. ?9 H4 B# s( R0 v; Z) q
+ L( S! S" P7 a/ G" Y
1. public string[] Split(params char[] separator)7 [1 E" I- m$ c8 ^/ f
* M: i/ M! b: r0 z5 v' ~+ @! v
程序代码
2 j1 |, b& Z2 Tstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}7 W6 z/ O) j+ n: I3 B  T3 ?
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
9 l0 C/ J  D+ {) O4 n. S
. f5 v6 M2 R$ D" I, x2 e) n  Y2. public string[] Split(char[] separator, int count)
+ f8 ?! r, _( `6 N6 f) q" z# u% ~, t) {' h3 F$ d! ]8 k
程序代码8 _" D" ~9 @7 c
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}9 k* F; E' m7 @  Z6 f
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
9 ?+ x3 U! I8 Z: g  F- ^; H6 M0 ?/ s( v3 d: j2 L" K2 p7 g& w" [# ]9 |
3. public string[] Split(char[] separator, StringSplitOptions options)
6 n/ f' j1 a" I3 q; v5 G% \1 o8 a; k9 S  b  `' |- s
程序代码: |; B5 ?% y7 M( F9 ~$ ^& ^0 j, m
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  E) i% ?& ~" I$ m1 istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 V$ z( W7 ?0 n( a1 K

3 m2 w- M4 x! t" Z+ q4. public string[] Split(string[] separator, StringSplitOptions options)
! b- w3 o: j2 J! w' m  }3 A( _! J9 E  a1 B
程序代码; E# Y7 T7 I# v  k8 F+ q
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素$ }4 w( W0 F1 v2 d( M
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素. c+ i9 L1 @* r0 w

1 y) E  H) E7 x# j% U7 q5. public string[] Split(char[] separator, int count, StringSplitOptions options)
0 y* W" m/ z& |' h+ Y
% j! z5 d4 s) n1 p9 w 程序代码0 O/ m6 t  h& U3 k' i/ Q
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素+ j+ i+ o4 }: l+ e: F- s8 E
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) Q/ F* `# Z$ Z
1 b, @$ z8 \% c  L* P$ z
6. public string[] Split(string[] separator, int count, StringSplitOptions options)* A9 Y# X: v5 _0 Q2 s9 w2 g
9 R4 |8 I3 c" g; |5 `! A6 ?
代码2 L) z5 X% m0 R7 `/ _' c2 s' i
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( I  N( n2 A# T9 @1 S) Mstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-4 06:28 , Processed in 6.058826 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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