晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
+ S1 f! c2 S+ L% {$ m. K. w9 H. g: t" P2 e( n  @7 r) e5 R
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
. W# e/ h8 a2 O# o3 X3 d& V* V. q! o  d# c) w* y
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别8 t/ h% ]' R/ `  ?9 G
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看/ M' h4 Y$ D  `
http://www.itwis.com/html/net/c/20100506/8234.html6 s  k1 L4 v# Z  `1 [( `" w
& e, ~3 c) f+ ?7 {
程序代码
; y3 P4 p) N6 W3 d1) public string[] Split(params char[] separator)! c$ i2 A! w0 O- O. l% x
2) public string[] Split(char[] separator, int count)! ~/ [- j4 K& M5 z8 w
3) public string[] Split(char[] separator, StringSplitOptions options)5 W. m" i, V( A: u& ]+ y
4) public string[] Split(string[] separator, StringSplitOptions options)! r7 p* g9 ~& }( i: d
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
1 a% \  C; I. H' W: v) N6) public string[] Split(string[] separator, int count, StringSplitOptions options)) T" }8 m! w5 e4 q

& y% R$ C+ t6 A下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
% J( ?1 F0 z1 h0 m2 }6 B- Q7 l7 h. q. I% |% _
1. public string[] Split(params char[] separator)
& s! C& K6 i3 G* u" L& L2 W2 E
程序代码1 W  S) ]# ]0 Q$ H/ a3 W8 i
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}5 }5 L4 W4 `5 d4 y; W2 Y0 w
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}) l  i) b) I! ^- p/ U

) \- Y1 Z- Q4 i* s! l, d5 D. _0 \  @2. public string[] Split(char[] separator, int count)
- n5 x6 q/ ?! M% V3 r
9 J& ]# `- z. z 程序代码
2 i7 i" }" ]5 g  vstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}' ^9 k7 ?/ U: Z0 M
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
7 O4 e) V. s. J! j8 J4 Q
. i% Z: ]2 g; y* v3. public string[] Split(char[] separator, StringSplitOptions options)
! j! K: [8 U& a) X; F  t8 |
2 `/ a9 m9 e: R2 Z4 w2 S 程序代码
$ e$ K7 w, u' O( E* o3 ~" Ostring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素- s$ _8 l8 [; z' a  {! f1 S- e
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 _+ o* F; z- y1 u/ d
0 W' T& D& q6 x7 p/ w9 @' ^4. public string[] Split(string[] separator, StringSplitOptions options)
% v% O2 m6 ^4 O! E! o
- m# u9 V/ _1 i! o  A7 X( A 程序代码
* `0 e2 w6 J* k) \1 T1 G5 mstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素2 ?" B+ Y' r$ s- O( Y* r
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  c2 g$ l" A- ^, P; @% G' |. @4 D5 G( E: `# z8 F* m
5. public string[] Split(char[] separator, int count, StringSplitOptions options)* _! C- i5 L% Q0 ]' }9 p6 v
2 o1 A8 S* C  Y( B- c
程序代码4 |. H$ q6 g. U! f
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
3 d8 e) R: e$ T6 h% h5 t6 Q) w* f7 bstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ ]7 y4 v' t0 m
% Q+ ^, U+ K% ?6 r& J% n3 @, \6. public string[] Split(string[] separator, int count, StringSplitOptions options)
" p- Z# r" p1 K. Z
  O9 g5 |0 A* \6 Y% V) L6 f代码0 ?; _  m2 h) [7 x
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素3 B7 X* `5 G# M' O- m
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-1 17:08 , Processed in 6.065042 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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