晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
/ F9 S7 ]% q; l+ l
( C2 \6 m, d  t4 I1 w, ~读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
1 _% [" P& e) t1 b: Y3 h
; H+ l9 N2 k& Q3 x6 N6 M* d: M对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别- g5 V0 F+ ~' g# A5 T
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
, h* u5 q% i+ b" S7 qhttp://www.itwis.com/html/net/c/20100506/8234.html8 N' B0 i% v* d8 O
; D( a8 e& l) h1 a, X$ H% I
程序代码
) r* g0 G2 `1 L0 w! T$ H4 i9 I1) public string[] Split(params char[] separator)
3 P+ }- C/ b4 e/ ^2) public string[] Split(char[] separator, int count)3 B" S3 ^) d" ]5 H: f' G
3) public string[] Split(char[] separator, StringSplitOptions options)
; O" }/ y$ G9 n7 @- v5 d% |4 J& m4) public string[] Split(string[] separator, StringSplitOptions options)! @1 L- R% L  x7 |4 i3 g; X8 r; m
5) public string[] Split(char[] separator, int count, StringSplitOptions options)* M4 A* V# q. G* z, @8 w1 d! I
6) public string[] Split(string[] separator, int count, StringSplitOptions options)  f9 l( L# r$ `% {+ L* A6 M
  u: z) x& i& \( m* `: c
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* u! |) N% L: x; R3 q& x6 G
# c. w6 j" X/ i" j& X
1. public string[] Split(params char[] separator)
8 G: h: M) h. G. D! d: @# D+ ~
/ S4 C. X0 B& v: e* G' N 程序代码
8 R4 \9 x) I9 _3 p' Y7 ostring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}- j9 k( d0 q& j$ v# g
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}$ k# O: Y. u. }  S2 ~8 r' o
4 T3 }$ b2 h' \# e
2. public string[] Split(char[] separator, int count)- ]5 d3 u& d7 B9 Y9 x& K0 r& s. X

: j* s) _- t* E4 _" u& c# L: c. i 程序代码' {! D6 J2 o5 J/ }6 [+ M8 W/ N
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
$ R& v- @0 h/ j& a: xstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
- v/ |% s9 D1 D, T
( B  l5 v) y8 L0 ~3. public string[] Split(char[] separator, StringSplitOptions options)6 C9 h( l/ G2 v4 `% t- z. C6 w: k
9 N" y0 N) F- V# K
程序代码" \) ^2 ]7 }" N3 c8 B
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( Q$ S9 w& r: n8 J
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素  T. M% Y9 r# Z, d+ T3 W
( G) @* e8 m9 F7 l' ^
4. public string[] Split(string[] separator, StringSplitOptions options)  R7 {& o' E: g2 j9 ?$ X( Y

3 B# H$ M+ W* ]$ G4 W. M( I1 X 程序代码
4 R9 t% d: y) b7 r& ~* astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  s0 a/ o6 q0 [! y! I) r/ q( m" x! Tstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
3 F1 S& T7 ]  v+ c
. ~7 D; d- }7 C0 U% z6 Y5. public string[] Split(char[] separator, int count, StringSplitOptions options)2 S  V: \* d& d# a+ N* N. ^
" f  A+ z5 b6 G
程序代码
, Z. e( ^5 V7 E5 z1 s, dstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 B2 m7 @. p' ^, wstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 b, ~# s4 w% P

- ~' z% \( t5 t8 d1 m, |6. public string[] Split(string[] separator, int count, StringSplitOptions options)  \7 D3 L( J9 j) g. A. Q
& d* A; D$ j9 B5 A! Z9 S8 T. v
代码  a6 [3 l6 t# ]% d% G
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: q/ ?  r4 ^* \8 E1 l' ~string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-11 11:58 , Processed in 6.064686 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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