晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件# H5 K+ F1 ?% S3 Q. \$ N- e
! q' s0 h9 `3 J0 ?$ K" g- T
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码- e) R1 `/ c% S) L! p* ^/ r& n

( M  w1 X& S3 v1 H1 s4 h对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别* P7 ^+ M/ T% `7 k  d4 F# [$ s
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
+ V8 N0 E$ m" n5 b, P% Khttp://www.itwis.com/html/net/c/20100506/8234.html
* m2 o/ b6 S; o% M; a  }- [% \0 m& n6 z# [& g( ?" ]4 N
程序代码! R" I1 S3 b$ P; o2 ~9 y; H
1) public string[] Split(params char[] separator)% o$ l2 ?9 m7 v0 @, w! p' b/ @1 a* X
2) public string[] Split(char[] separator, int count). ^" ^, f- H; y: y8 J* a
3) public string[] Split(char[] separator, StringSplitOptions options)
1 z9 N7 }3 V7 Z& U* f  ^  n4) public string[] Split(string[] separator, StringSplitOptions options)
& y; B2 M. |8 }: L8 M+ B5) public string[] Split(char[] separator, int count, StringSplitOptions options). ~( c: t8 y; c" z# O$ @
6) public string[] Split(string[] separator, int count, StringSplitOptions options)) {8 m6 h8 x$ u( V7 ~

% x0 i+ K4 m4 _* ~  I8 X9 S" ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):' M2 C' B6 j& a( y
* w7 J0 y- K: O  H: ]
1. public string[] Split(params char[] separator)0 R1 D& |( ^8 F9 r: v8 E

, A6 x% h6 K8 q" |8 O( s 程序代码
& c/ [& H+ f1 a& v( {8 R0 Mstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
2 q! R' a. Y' v, B8 A0 B3 rstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}# h0 O4 J' C$ B2 `8 ]3 r
/ E! l5 o) {, M$ ]* O' U5 N& u
2. public string[] Split(char[] separator, int count)% c! P) z5 K6 O3 I7 s

, B" `, j* F+ a* i  [ 程序代码2 n7 V( S* C/ e
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
( @$ A: u: D! J* \3 M# n% Gstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
: x0 l" }4 R$ b& p* b' u6 V; L
: M6 N) Q7 K: R5 ?3. public string[] Split(char[] separator, StringSplitOptions options)
5 ^) `& z' ~& W3 b3 P. @+ t6 e: U8 m7 J
程序代码
1 \- ?" X2 N+ L3 R# H4 H8 qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, e, q! ?7 \! A( D3 b
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- ^7 i3 N. A) {2 q. h9 _8 o# Y+ x% u) ]
& w" ~  e" F* f
4. public string[] Split(string[] separator, StringSplitOptions options)
) A% q0 l' I2 N& K$ D- C9 |; G) S3 E# u( p
程序代码
1 I; j) ?* v. K* @0 ?* Ustring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 _: t* F7 G8 z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 f1 r3 `0 p8 M& Q. I

) \, s5 W; Q! }6 K" `5. public string[] Split(char[] separator, int count, StringSplitOptions options)1 W( F4 G6 \  x) D

" I$ }. n: P% x2 R3 t 程序代码
# L1 \- n. B, Q  \6 k+ e* G' Vstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 V. b5 n2 \' l' _string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素. j* I# U9 A9 }7 m: r' Z
: v3 b" v2 `5 |- F
6. public string[] Split(string[] separator, int count, StringSplitOptions options)$ T" {) K0 z9 T' Q
! j$ S1 i1 B0 T( [4 Z2 b' {" l. Y
代码3 g" E1 k2 X/ ]
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 Y3 T( ^, R! W/ h
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-15 02:41 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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