晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件1 r5 L; Z1 I+ ~' K
& O( @$ s) C( x2 C" @  j
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
1 _0 m1 B' }- x, O* Y
- v+ }$ {, i6 V- c6 n8 E, B- b对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
$ ?: e, T/ b' {/ R9 s7 x1 ahttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
6 O- B- M# I2 N! O" n$ @http://www.itwis.com/html/net/c/20100506/8234.html
3 w0 Z  |! E* n' ^/ b2 r
4 L2 m. L, ~! a# B/ c+ k1 C1 z程序代码' O( B, O# i) v" |  k  I3 B
1) public string[] Split(params char[] separator)% y4 ^8 H: z# X/ Y' |* ?
2) public string[] Split(char[] separator, int count)
& }) Q+ c) f2 z8 a& p7 o3) public string[] Split(char[] separator, StringSplitOptions options)
' F6 g1 Z6 v( t0 L# `4) public string[] Split(string[] separator, StringSplitOptions options)
) g0 X" C. A3 O5 k5) public string[] Split(char[] separator, int count, StringSplitOptions options)! v8 V7 ]6 b$ W" s
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
1 y- ^* A' q, _$ s' Z
; M0 h- @* V) M1 \: q: d) Y下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
- V, Q/ g. ~) N4 D' p
( f% M0 m" h5 J# \% q1. public string[] Split(params char[] separator)
  S6 W- `7 F" B$ [9 n( [: T) @+ \/ a6 z/ n: h6 u5 p0 O
程序代码: d: W' J8 e: U
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
& g3 ?; \9 n6 R! m$ hstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
% V! o6 J' c' w: f! z$ z
) i& K' \) y; z+ L2. public string[] Split(char[] separator, int count)0 n1 g* _% }; ~; ~/ [# E8 H
4 K. Z1 ^$ B: d* z! P
程序代码8 G( Q: V/ |2 J- |  a
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
9 t$ c4 t8 U6 }3 ~string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
1 O* }  ^: u9 P" q0 O: g
/ J- p+ O+ J* c9 n! B- F1 w, t3. public string[] Split(char[] separator, StringSplitOptions options)- |; y6 K* J9 L
! d1 F" H$ w" t# L8 s/ v# H
程序代码8 j/ r- m% _2 B2 C" f5 j
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
2 r' j& d1 C& N, e4 v5 w, {string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ e9 s$ ?; t2 G
% t3 w2 s' N6 Q& R7 j( e9 E4. public string[] Split(string[] separator, StringSplitOptions options)
+ u5 ~6 C4 g8 q, g. K' V; }. Q, F6 k6 T5 n- A) ^
程序代码
" }' x2 G) l- p4 B% Wstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' o5 E9 R& g( Y- _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
" v  T! O  m& H- R' a! x9 g, A. @3 N- d& E' m
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
+ z4 C0 ^: z5 R) e- G) W2 Z& x+ U5 E" n
程序代码
  G- g7 f, S9 {4 j( b3 Astring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素/ E7 K' K3 o- J6 J
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: e  r7 ]2 a6 U0 f( o* y; y. X$ S# c- C- e$ k
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
7 ~& [6 G9 }1 R6 D; q5 J  y: G6 v" s; c. F0 a5 `/ |. E9 E) Z
代码
3 T( a0 p6 w: J7 \. astring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素8 _' v" f. [7 n/ d( K* m3 j  a
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-4 03:34 , Processed in 6.063709 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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