晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
% Y" h" C% ?( G# {- @. J0 X- L& ]7 Y$ u( A" y+ R
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码% c8 _$ t8 }& _' |% J
% V: p1 M# m. O8 C$ X  @% o
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
. M% C( r% R) Ihttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看8 j2 i$ `! j* {- W" ]: S# n! ~
http://www.itwis.com/html/net/c/20100506/8234.html/ N; `% r+ \  M( y1 p

, y. t' c$ y5 Q程序代码
3 c! u9 Y* X  M4 m1) public string[] Split(params char[] separator)
9 t8 y7 I/ x+ E0 l. L2) public string[] Split(char[] separator, int count)
! k- g/ @5 l& A5 I" e6 f3) public string[] Split(char[] separator, StringSplitOptions options)# Y! K6 K3 g! B9 J" V
4) public string[] Split(string[] separator, StringSplitOptions options)) i+ z9 m' E. l' i8 g  P, ]
5) public string[] Split(char[] separator, int count, StringSplitOptions options)& T+ V" J; j. \! Q) A5 Z
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
  m( p% N9 }$ w7 ^; i) c% w/ ^
( ]4 Q: i& `5 K* u( Z# e$ d下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
* L# B' @; \3 h; q8 L  \' v  A8 R. w  U1 p! i& x- y/ Q$ A( v
1. public string[] Split(params char[] separator)' w- r5 q" T. n. z) u# w: O

& X% Q. Q+ m4 h* @7 N  V4 i: C0 A 程序代码
  x3 c% h; _/ \. ?1 [) bstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}# U. ~+ h0 V* I) J* {7 e) B& m
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}' f) x3 S! l  Z  {

( ^, O% E, c) C7 c2. public string[] Split(char[] separator, int count)
! @: M% z+ A/ L& d2 x# v9 w9 Q  J+ s$ j* H) |1 Y' y: h
程序代码
) E* q. v- B0 b% T8 ^/ Zstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}" n; z) m& c/ R, Y: V' M+ N
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
, {8 _( \) F4 w: L" h, J" i$ e7 c. p$ j
3. public string[] Split(char[] separator, StringSplitOptions options)- y8 R$ I2 x! f' D2 Z( i* ~, Q  g

4 `: l( i; g. T- e 程序代码
9 A5 O: ?" \  D5 istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
+ O2 H" r$ T4 ~( X! ?3 T/ cstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素  V3 _6 i9 A, }" v  y

0 l  a, Q; O2 G0 W6 C: B4. public string[] Split(string[] separator, StringSplitOptions options)
( f; i3 w; L  D! K0 P# {* o9 J) ~$ b8 y& ?2 ~' c* T& a( M
程序代码
# [) W' T7 ]3 {7 Ostring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素: d1 Z7 Q0 ~8 \- Z, F6 I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; A$ A6 N$ T1 |: H. y7 O
0 C  ~8 T: v' ^3 N2 L5. public string[] Split(char[] separator, int count, StringSplitOptions options)
1 p  B, P, o, A( h) g2 N  r  T. i; h4 [1 P
程序代码* X+ \- [( F4 e7 C
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素! E) M: T7 `7 y  @7 I) r! y
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素5 r: [2 H. Q1 K7 |4 y: q1 p: d" e8 x0 @0 ~
' v8 I" y7 [0 [
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
) O' ~( v5 N% Z- w# u, G; F7 \" c. L3 a* g2 @9 }8 `
代码
* E$ a2 }9 |1 N; Rstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
6 Z" j$ c4 N+ d# X) Rstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-19 03:09 , Processed in 4.754579 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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