晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件. F: l% o- b( V% w- C
* c0 W( k) u% B  W% F, i+ A3 B" }
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
* n+ C$ ?, Z0 m, ~/ G
2 `5 E7 F7 p9 _  \# Y( n对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
" D( n8 U6 ], |0 r) q1 ~( P8 qhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看  H  W( q* r( F# r7 J
http://www.itwis.com/html/net/c/20100506/8234.html
# h3 B8 |/ w& U. U4 O* ^0 b7 ?
' M. m9 _, _$ P7 r0 `+ G% p7 J程序代码5 x; E# ~2 Y* X& G1 m3 P" e; k* J
1) public string[] Split(params char[] separator)  Z; H1 O7 K; T5 K) a5 j- t
2) public string[] Split(char[] separator, int count)
* `) l0 N& V7 }: {& \3) public string[] Split(char[] separator, StringSplitOptions options)5 s- W( M' F+ @% \
4) public string[] Split(string[] separator, StringSplitOptions options)
2 N3 s; Q  t! J) C5) public string[] Split(char[] separator, int count, StringSplitOptions options)
; B2 I# k9 q0 Y% u0 _/ R" i, f& n7 o6) public string[] Split(string[] separator, int count, StringSplitOptions options)! }: r0 y7 \& N! E# q! I
4 I4 w% j) f. M8 l- }  V
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):+ U% I5 j  z, q; |3 @+ m! ]$ q$ i

% u0 W! r" C* I- ~, C! L. G, p1. public string[] Split(params char[] separator)# z9 \& `, w1 R; _2 W2 g
( x! X5 @% J0 U8 }/ y! [$ X; n
程序代码
2 D4 v( Z/ J$ ?8 x) O  P' k" lstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
+ z4 z4 j* v) L8 mstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
. z. M5 q! C/ C% t, ^4 {9 H3 {4 l5 j: `
2. public string[] Split(char[] separator, int count)/ t- D" S& z, \* G: F/ ~
4 o( Y7 B% E. _: v
程序代码
  N$ y; B; _% C. N+ Q5 |string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}7 @+ @- V8 r+ ^4 u# H; l' s5 Y
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}' D; K: _. C  r! E( S5 ~

, C3 y* M- u. A- U6 D: Z# S3. public string[] Split(char[] separator, StringSplitOptions options)0 |* H1 [( a) q) s) p5 @1 l

' x1 M7 O1 K2 e6 T 程序代码* |8 E! \! U) `. O! @
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! ^/ h% ?0 m- istring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 c2 E" h$ N; d% k* u& q" I

$ O( ^, q8 i0 @7 A' A/ p3 S+ P4. public string[] Split(string[] separator, StringSplitOptions options)
' Z, S, o( }* q! O6 f7 @/ _2 D% i* W( ?! ~- f" H
程序代码# W$ h, ^! Y: l
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素/ |& W( k( l4 Q1 P2 e; _+ {
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
# H. D( l. E/ ~: x( T+ X: p# y3 H# c$ O, N* ?6 S
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
7 W8 @, R. B" e$ C+ g7 g, F0 h/ C+ S, m
程序代码" N9 e/ t( k6 O% z) T- G# e
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 T- F# C. S$ Bstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素( o0 e0 L7 n- A% C, f! M+ h; s, N2 B

4 X4 H; D3 l& l6. public string[] Split(string[] separator, int count, StringSplitOptions options)/ T- v! ], L' P( P1 C8 z

1 e: O/ ~$ u1 \7 O代码
8 Z+ a. Z. Z0 |# j( d( E3 b+ ^string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素3 T4 Z6 J9 b! [. f- H
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-26 00:41 , Processed in 6.064065 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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