晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
+ X. ]$ h) i2 X+ q$ V5 r& X
: o0 \% |2 G- G6 v读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
5 h" j, M; X. e) |" G
) q$ R( `/ }1 g5 p4 A对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( n1 J2 X, e$ ohttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看! S# b0 a$ x1 h5 s5 |- ?) K4 h
http://www.itwis.com/html/net/c/20100506/8234.html0 ^. B) F9 N4 J8 v6 A+ ~8 R
% H5 z% Z6 x5 h7 c4 v1 \
程序代码
5 i4 m1 v' b5 o" \1) public string[] Split(params char[] separator)) ^8 M' ?' G5 [
2) public string[] Split(char[] separator, int count)
) {5 ~7 I. A1 Q  I2 c' O7 p  v) o3) public string[] Split(char[] separator, StringSplitOptions options)! e, t7 _' L$ Z6 t. `
4) public string[] Split(string[] separator, StringSplitOptions options)" t1 {" h/ d  u2 @* S0 r
5) public string[] Split(char[] separator, int count, StringSplitOptions options), W0 s- P  M( S5 }1 s: ^: Y0 G* \, S
6) public string[] Split(string[] separator, int count, StringSplitOptions options)% h& H+ w6 p7 ]) K, q; n3 \

: \4 j" U* Q7 e) Y下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
6 q2 p, [9 |5 b& g8 [: b' R  K! Z' B* K) H) m
1. public string[] Split(params char[] separator). y7 E7 S) P+ Z; b
8 x/ }/ Z5 W3 {" y9 }8 P4 I% t
程序代码6 O" y# i) \; D  |: ~
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}" }  b- o* Q2 d0 `. ]
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}: I% S/ Y1 I6 c6 y) a% H) ?

" j6 |$ A9 |2 d2. public string[] Split(char[] separator, int count)! B6 ~+ q1 w% V# u/ @& f
& C2 Y$ D( J" z
程序代码
% }/ {) P0 B* v% [/ `& b( kstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}( |: C# C% g4 Z) {+ }) a
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}5 ~( a9 O7 o+ U: J3 _. N$ L* R
4 D4 ^0 d. N! ]. l
3. public string[] Split(char[] separator, StringSplitOptions options)
( t4 ^' v  V& E$ c% j# Z+ y
/ e9 S8 v8 q0 O! g 程序代码" o# ~7 J) _* A1 X" o9 z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素+ G; u9 w! m, |/ l/ g" C
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- u( I$ ~9 E* Y; l9 K5 t8 c( M
4 v/ C. U5 N- L" x9 Y' O
4. public string[] Split(string[] separator, StringSplitOptions options)! }. ?; t$ u6 L( ~

8 N7 m4 v- ]; _& w/ n 程序代码
  \: c0 B' I- w( v# O: astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; @/ r6 K7 Z" U% e
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ ^4 y5 o8 Q4 E" W

$ |3 B/ t5 Z4 j6 q: n* @1 O5. public string[] Split(char[] separator, int count, StringSplitOptions options)0 q+ K1 h7 W5 j) k. H5 g# Q$ L

0 J7 k+ J; V8 r3 l0 Y* S! |- g 程序代码( t4 m$ ?( G* w9 T  q
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素" y9 _* Q% o1 e
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素% X5 g/ A; ~( H- ?
2 m! y' Z0 |9 o" `/ M+ Q8 m# E
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
; F4 `% m/ g5 a$ H" L- ]: _+ j: {
; v" D! e: ^3 U4 @8 P6 [代码
% }) F  Z9 R* h$ J( A+ gstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
, N% t6 y* R! Xstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-4 14:35 , Processed in 6.072853 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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