晨鸟科技

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

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

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

) }: C0 N& c9 O+ E/ q$ C读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码9 e9 Y5 K# X  \- a

! y+ V$ |3 V' k9 M+ Y对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别3 S* r6 ?$ k8 W9 y2 @. O- w: Q
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看( D6 W4 P( a( @; R9 |4 Q* n! @4 G3 T
http://www.itwis.com/html/net/c/20100506/8234.html5 h& n$ U" b6 Z" s2 _, o

0 m3 x* X: ^6 Z! c: B) W程序代码) B1 v8 G" O( `- f1 r1 i
1) public string[] Split(params char[] separator)
" D/ H# Q2 f+ ]4 M# R  H% H& m2) public string[] Split(char[] separator, int count)
- D7 P, e$ x/ I1 D' t! @# m7 v3) public string[] Split(char[] separator, StringSplitOptions options)2 ^$ ?( [7 R4 H* M6 z) X
4) public string[] Split(string[] separator, StringSplitOptions options)
+ M7 B+ H' `* i, e& l5) public string[] Split(char[] separator, int count, StringSplitOptions options)! ^) b/ D; P9 [+ n2 Y8 j# p! l9 v3 q
6) public string[] Split(string[] separator, int count, StringSplitOptions options); S- P: z: b9 a( M8 T
& ^" H& H/ }8 \: a2 s
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):( l3 J) ?# I6 E

; g$ f0 @& Q% T4 c. a1. public string[] Split(params char[] separator)
$ Z# K4 l/ J; A" X" ^) J. F( q4 ]7 r& D$ W/ Z$ a
程序代码
: ]3 m8 k4 H7 n, ~string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}$ S1 H6 \( C, I( Z
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}& X/ b, k$ z+ f

9 i8 K9 F  W) U3 S4 O0 W0 _* i9 I2. public string[] Split(char[] separator, int count); |% t0 d9 U; S  i6 y. ?
" U, \. s# n9 x. d- z' ?
程序代码' ~7 c( r. I2 q9 _4 s  @
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
5 A3 S! ]* s  h. _& e' Z3 wstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}$ a1 x$ O$ O- X  Z8 a1 Q$ x5 A" k
6 }" Q# j2 ]! m9 L5 E
3. public string[] Split(char[] separator, StringSplitOptions options)
; z0 g" x2 _* o% u+ b: j  K1 ^) ~; U, U) @0 w
程序代码
0 L% u; V, d8 k% M% B2 ^9 a' {5 Wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! R% u" f& c, E( R3 astring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 j7 P; i) Z7 a/ S; C
8 U, r; P; X# f4 v: S) R9 N4 h
4. public string[] Split(string[] separator, StringSplitOptions options)* R* t5 h/ q; r
4 p( N3 Q& R8 k8 U2 U
程序代码/ R5 k# s7 B7 P: A* X4 L
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& W) l5 M! u2 I! E" O3 ~( U9 {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 W4 C2 D2 }0 G

* J+ t% _' p* v8 f5. public string[] Split(char[] separator, int count, StringSplitOptions options)9 o, U) l- k) U6 P
1 }1 _6 q2 }9 g$ s- t1 X
程序代码% q8 H* N/ o( _- @
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素7 `1 g3 j7 f0 C/ ?; C8 e8 ]+ o
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
! b# k: o1 D* c+ [  [1 P
4 K$ D/ w0 z+ g5 j: z6. public string[] Split(string[] separator, int count, StringSplitOptions options)+ R4 ~# A$ P% I/ I0 q

5 s, I/ l1 G7 c  U8 M- M代码
5 Z# V+ a4 F! e# zstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* L/ @+ F7 s, z1 H& }8 J- l
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-11 09:20 , Processed in 6.089101 second(s), 15 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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