晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件2 Q3 [; f) H* [3 ~$ K3 ?
5 Z0 h/ y. Q* c1 F0 ?
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码6 S: t4 z5 g& e+ t9 v( X* R7 K  g

& t1 V6 L! ^- N对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
  A4 [( j/ [/ a3 i9 X- D+ Bhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看4 g; W' k9 l3 c
http://www.itwis.com/html/net/c/20100506/8234.html# _. r& ^! U- Y, C: v
8 W4 ?( `8 z% W
程序代码; c0 g- M4 c, m# S, v: W, }/ t- l  ^
1) public string[] Split(params char[] separator), m' {5 a3 f: {& z: _
2) public string[] Split(char[] separator, int count)* j% m& f( a( l3 A9 P5 ~
3) public string[] Split(char[] separator, StringSplitOptions options); [! [/ \& g) S+ F& _' J
4) public string[] Split(string[] separator, StringSplitOptions options)) a& ^) X) |' [( S( t6 F" R
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
& r+ q( i' t( W% O7 R6) public string[] Split(string[] separator, int count, StringSplitOptions options); l7 P- ]/ K$ t8 G6 M* D: V
; L# ~* k- _4 g. \
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
9 @. v, x2 K* I7 i: H, H4 l% Z; P, ]  ]3 R
1. public string[] Split(params char[] separator)) W+ E4 l' s& J

0 [1 u& j1 }$ D5 S/ ~# @6 n 程序代码8 E3 b! z% o  G2 x& D+ h8 }6 N
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}5 B+ q, _( T! n/ H/ O! E
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}- a2 }5 t) @( y; d
1 Z. k* U* K1 n
2. public string[] Split(char[] separator, int count)' @% e& A/ H- T0 j# t
$ p2 `. n2 W, R$ x) }
程序代码
) i' S1 b- X; ?7 {/ R% Z- qstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}: F& q' N% C/ _) `! \' O% x
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}/ J' Q' B  J+ ^- W: S
- U% E9 J- b7 V& ^2 p9 }
3. public string[] Split(char[] separator, StringSplitOptions options)
& O2 y* c+ P# N" J8 Z
8 b3 j; ~  u; o1 z& D7 K8 \ 程序代码. F2 \% V4 y1 K: e% A8 `
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 Z9 U! }' r# ]. M$ A* rstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' `# j) g. N% I5 I1 i8 D
# o6 B* ?- p* e0 w8 c1 d) i( p4. public string[] Split(string[] separator, StringSplitOptions options)
) W; t5 P. }" p# I  o& e
, @# Z  q/ K3 L( X4 y' q/ ` 程序代码+ P+ v) `% z( i* R, }3 ?
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' Z4 n( {, y. Q+ ^1 i  ]
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! y' }! o. r5 Q+ o# r- m

" b% |7 w$ D1 O4 ?5. public string[] Split(char[] separator, int count, StringSplitOptions options)
& [& |+ b! r! {, q3 @
: O6 p3 k! Z* S& E/ h# v 程序代码0 h. h( T4 T* V8 s( A0 s% E
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) R" |4 t8 C# c/ H' b7 Z
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素1 A% O( Z/ f5 X( d, ^+ v& V
" h% F$ m! q2 m
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
7 x/ w! x; ~. e# C( l1 s; d5 w- S: c* i& I9 `
代码
: z" j6 [) `) p  w  j( n- y- T- ?+ nstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
5 s. t  v/ R0 ?- E- zstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-31 14:13 , Processed in 6.070545 second(s), 9 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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