晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件+ C: Y5 H4 o- T$ s0 j5 t, g
' d1 _0 a+ y, f! P
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
, N& s/ s' ^( v, H$ \/ r8 @7 R  {+ u, \  N- w. T2 L; K
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
2 Z, ^# s' }6 G8 n, xhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看0 A# Z1 d( W. X+ L8 \
http://www.itwis.com/html/net/c/20100506/8234.html
: s! }/ p$ D4 j6 c' ?
4 X3 M6 n8 _7 \7 K. o5 B" [& L; }' y6 G程序代码
9 [! @! t9 ~, ^- a# t( ?1) public string[] Split(params char[] separator)# C6 L% E( U$ t  Y* |/ H3 [
2) public string[] Split(char[] separator, int count)0 r% n  m9 j& |
3) public string[] Split(char[] separator, StringSplitOptions options)! t8 T- d" s! {3 Y+ l
4) public string[] Split(string[] separator, StringSplitOptions options)1 ~; u; }( G( j7 E
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
3 g! C4 D9 y2 l& N9 I3 w2 V8 R6) public string[] Split(string[] separator, int count, StringSplitOptions options)
$ r( K6 E) S7 g- m5 l1 o" P. f3 B; V6 \: w% v
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):/ L3 L) [) F. d% B; o' b& B) @) z. U
; G- b& n- x. ^: _* A6 D3 Q" M
1. public string[] Split(params char[] separator)  ^* |7 d6 E2 L. Z& j

: L: H! b6 f8 H$ q9 w& x 程序代码+ B# j2 l, a# ~; L; x) o# e! D% {2 V
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
5 s; V2 G! e* l3 rstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}% a2 _* l( _" T: Y% {4 @: M) ~

$ C9 g4 N5 A- m+ O  ~0 `6 z8 k2. public string[] Split(char[] separator, int count)
3 B$ e7 z% M, m* K2 f5 P  ~0 J' u5 H& [) W
程序代码! m: g# M5 I2 h% t% ~
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}9 X3 K/ o( a* z- h/ {
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}! X9 r8 p8 }, G. T! c

# c( Q# i! u0 P6 ?0 X, a3. public string[] Split(char[] separator, StringSplitOptions options)4 P! H* D( g3 ?! z& O

: D0 ?0 ^+ K: ` 程序代码( D1 G9 H! y& v! k) S' [
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
' u/ d1 b" y7 \; Z4 X$ Jstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: I/ P! d* o8 H; }' N# H# X% f

7 Q3 M# u* a, J$ C4. public string[] Split(string[] separator, StringSplitOptions options)
% J/ m, [- r7 `, M' N9 N) X5 v. ~  S1 d! [- Q
程序代码
) i2 \  w. o: h; H" ]string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素3 _4 E5 ^1 M# z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 F  `% w) ?' h( f. D* R9 K& q9 o6 [
& }6 B3 B, O/ `: k5. public string[] Split(char[] separator, int count, StringSplitOptions options)
  \' z; z) Z4 B* k" Y2 I8 H9 W: c) a2 V6 c
程序代码5 u6 B/ j+ D9 Z+ N6 R
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素" n3 J/ H# K6 ]4 l# E
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% p" w9 o  i- d, ~- [6 N5 e' h
5 m- h) M7 C. v7 T2 \6. public string[] Split(string[] separator, int count, StringSplitOptions options)+ n6 _4 ~  h. w6 M- ]& j
2 Q! _, K$ Y+ f  w, O& v% q
代码
9 l. n( P: L: n& a  Kstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 |, _% p# c; y1 mstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-18 03:28 , Processed in 6.070901 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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