晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件# ]6 e; {) b3 \

% @$ ^5 ~# W$ w* L# t读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码$ z5 A- Z2 o+ n. z) C2 g

/ p$ M( C6 u8 m& M2 u4 J5 q对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
8 Y' i+ w3 M/ B. v4 |8 O* l6 P; m" {+ nhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 G4 q, {* q/ y5 z. Dhttp://www.itwis.com/html/net/c/20100506/8234.html
2 f5 A; C7 _; P" r& d1 v
+ m2 t2 p6 E( P( k% H程序代码+ I- p5 V+ z0 J
1) public string[] Split(params char[] separator)/ V" n! \5 |4 F9 D0 s
2) public string[] Split(char[] separator, int count), f6 U& X% l' B) |+ d9 k
3) public string[] Split(char[] separator, StringSplitOptions options): S, N6 Y4 I: R: _7 l
4) public string[] Split(string[] separator, StringSplitOptions options)" m  h/ Y" Y8 s, A  @- @4 T  C. _" T8 [
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& A6 E+ o" H  D3 s5 m6) public string[] Split(string[] separator, int count, StringSplitOptions options)
: t; @5 _* G5 Y: q$ b
  _" \( z* Q# B! n下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):6 [( t& w2 Q) e) z% Q- \& J

) T) E2 a4 Y* k4 }1. public string[] Split(params char[] separator)
3 U' u& f+ T; Z. L6 A
' X; ^7 e7 S7 O5 n& ^! h" p9 z 程序代码0 {1 B0 Q$ z2 y, H" B5 o0 A. t$ u
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
1 g: C" @. f7 e, v2 lstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}! ?# E: l0 n6 E4 Q4 }# @7 r
; ]( `" d) z+ t) h
2. public string[] Split(char[] separator, int count)- x% h' w- {. R* L
" Y; h% i  V, B( y7 S/ ?' t
程序代码6 h$ z2 i9 `; h4 w, Q7 {# ]0 `
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}/ _4 b; [* z4 Q' H4 P3 V. J
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
) _* k5 l! v9 N6 w' F4 e" i$ G4 N; r  K8 M- \0 p
3. public string[] Split(char[] separator, StringSplitOptions options)" r5 B- b2 M+ Z, o

9 i+ b: h/ d" ~! W7 n 程序代码) x8 w9 a# u$ O, a) @
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
+ [/ f3 O! [  N+ l1 kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, R; Z7 R0 H1 z: K% ?% s

8 @( T1 p0 |( U. Q6 z+ b4. public string[] Split(string[] separator, StringSplitOptions options)
3 C3 R  |' G& V! c) @7 A: `# o% T, \3 q
程序代码! E# j& O6 i% V* u" E
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素  n: [6 K6 |  o# ~( b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 o2 I3 o+ v- w, H0 I9 E/ r) A( r! b# z; Z0 k
5. public string[] Split(char[] separator, int count, StringSplitOptions options); p: f' ~) v# |
& L, i, r# U. \$ P  K( R1 S; q
程序代码
' _) ]7 g+ {2 Cstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
0 W1 c: L1 f* `) a$ ystring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* |" A9 s8 G$ _) b  I/ N% A; n( A1 C: E7 p' a# @9 U5 j- ?9 B
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
. i1 A9 J& O) }$ U
; V: i  N/ w! D9 K$ W9 Q代码
8 W. I$ T% J) U' v/ xstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* t- z0 w# b# g5 M( l' A
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 15:03 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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