晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
" E4 z2 \. g3 f) i
% w- E' H3 t/ ?; b. ]$ }7 b7 w读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码- N5 o! Q2 f! Z

7 s+ n" v1 b/ R( }, \) b对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
. B$ s. Y# U7 W' |" `http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
; H( ]# m% z: T3 y9 Lhttp://www.itwis.com/html/net/c/20100506/8234.html2 \( o/ z0 z; W) G
/ X6 ?% k3 a5 f: _: r$ {; Z
程序代码
* E4 _8 R% w  u8 Q% x% t1) public string[] Split(params char[] separator)
' _- L7 n9 u" ^7 H2) public string[] Split(char[] separator, int count)& c2 z3 w0 I8 S% a7 t
3) public string[] Split(char[] separator, StringSplitOptions options)
2 W# R2 F# O. ]  W6 E7 p/ ?4) public string[] Split(string[] separator, StringSplitOptions options)
2 |5 V4 N" o' q5) public string[] Split(char[] separator, int count, StringSplitOptions options)
9 p; L! ~$ G3 Z. j* d: r; |6) public string[] Split(string[] separator, int count, StringSplitOptions options)
1 w$ v, N: [+ I! R
; x/ N9 H& I  o下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
, w! [5 A; N: \5 e2 G9 G- {" H2 Z0 |: v" X$ _; K* T( E+ j9 B
1. public string[] Split(params char[] separator)9 I4 U  O8 G6 g! h

1 C7 i7 A8 G; ]3 g5 p  O 程序代码% x" s6 X, r- L3 k7 A  J0 f& j
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}) B$ H( |. K. M% Y, N1 ^) `3 N
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
; ~9 P& @6 I/ J0 z* t* _
% k' E+ ^3 m. T) J  A9 }2. public string[] Split(char[] separator, int count)
' T4 N$ C: m9 R3 d+ w; X7 M. H7 B
程序代码$ n6 K. W  q. i: w
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}" p4 }0 C6 P$ ~- ?
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}. c" A9 L; f2 d0 q3 S

! y0 g. V' d4 P3. public string[] Split(char[] separator, StringSplitOptions options)
4 g3 d3 f  y# H2 z' o' S; b  m  L. b3 _
  I7 T5 c& Q$ k0 d 程序代码6 L! m) O4 s3 S7 B/ w
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素. T8 [7 k2 n- C
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 |0 ]8 K8 Z! q

9 U9 p! T5 f. R) t( B' Q4. public string[] Split(string[] separator, StringSplitOptions options)
" f) K' c7 ?- q1 e6 T8 w( ?% @2 S( p9 D1 k
程序代码% d2 t7 g4 H/ T4 L' _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素8 h: I6 G, i8 H" l* j: q3 ^
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 R* |3 M: l0 P) l! L; S
1 o4 I' J0 f- m4 o7 H5 a3 `# y  @
5. public string[] Split(char[] separator, int count, StringSplitOptions options)6 r' n& K' V3 L9 i) H. A
9 G# J/ L& |! n9 ?+ {* l
程序代码' S8 W9 c6 A: s: b( d; x# Q7 t# [/ E
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素7 p7 E$ \0 w/ \
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: B. x5 }/ l4 n( y: O; V( I8 }' @5 Y( P. D9 t
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
4 G# a5 a: f# r
4 }% u$ T6 Y) ]; d/ ]1 U代码4 \) l/ C3 ^# i! z
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素9 n7 ]/ T" @# p) r
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-16 05:34 , Processed in 6.061756 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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