晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件( c* P; A: d5 F  N: J( a* O' Z4 H7 P- F

) K  y! e! q/ l* F! ?读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
( ^4 W* z3 \4 r5 k. z- n
! v; |+ {+ n% m" g7 i1 L对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
. l/ W+ [+ @. L2 r% Zhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
: ?2 h, G6 T) X; k$ Dhttp://www.itwis.com/html/net/c/20100506/8234.html
4 J$ v+ G. l7 \  ~4 X; P1 k2 h. g& p1 o& l; S6 s
程序代码
% t2 U  G; T; v# Z1) public string[] Split(params char[] separator)+ H( Q( v, F$ C- H/ }, a
2) public string[] Split(char[] separator, int count)
: c% r/ G) ^$ c) q8 a. ~/ Y3) public string[] Split(char[] separator, StringSplitOptions options)
0 X0 D* P) ~1 D' x4) public string[] Split(string[] separator, StringSplitOptions options)2 ?/ m: S, y0 p' ?/ t
5) public string[] Split(char[] separator, int count, StringSplitOptions options)" P! C* W" K* N! y& O2 g
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
3 y! p5 H: C+ t* u9 O1 `7 ^1 c0 Z$ Y( `0 K( Z9 Y! N
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
$ h* d7 O$ q" N5 \5 a# Q
9 t/ j; w' t% J5 M1. public string[] Split(params char[] separator)7 f- c+ K' q5 T- {- b! Y% p# t

. c% [. B$ b+ x# i, r. J, }2 C 程序代码
8 ?2 O3 \' W8 l+ R; C8 I1 Xstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}" e& x  x3 X1 e$ K5 ?
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
* _- C5 r) r5 ^; X- U0 j+ \2 `8 u; S7 ]
2. public string[] Split(char[] separator, int count)$ D+ N) D) r0 I  C
3 j! j/ U: q( t4 w2 C  Z
程序代码
( b+ c. |  u' W# y  Y8 c+ ^+ ~string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
1 W2 U- F3 X% A8 Jstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
) J5 p; ?; u  @0 X5 {- `4 f! e, T& q5 Q- J9 j
3. public string[] Split(char[] separator, StringSplitOptions options)
+ g0 j4 D/ v! ]4 z% v+ l0 ]( S2 W. A5 O9 `! ]8 S: `" E
程序代码/ Y8 i# @( R3 e8 C0 G% s- U
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
1 D" Z- h3 G8 f' M5 wstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 i* X- S* Q1 P4 C) s; K$ s1 t" @
4 z1 Y) X& A2 R; e2 ]  o+ F' ]1 {
4. public string[] Split(string[] separator, StringSplitOptions options)
4 z7 ]: g# z0 Y* a# a5 l+ j0 Q7 p1 q) t
程序代码# f; O5 ~8 L' t8 a
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素: x7 C! v3 ~: D, w7 {
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素% k1 j, L7 F8 d) z) }

# w6 w7 f& E' D% }' i/ ?* E5. public string[] Split(char[] separator, int count, StringSplitOptions options)0 y5 x- y( z' i% B
  y9 w2 w& D4 m3 K: ?
程序代码$ v0 G8 z7 V, ~% o7 g7 R
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素8 X" ?# x& b' ?7 q1 I! }
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  O+ d# g3 Q9 H+ @# r" [( y
( k& A5 d! z8 Y% ^0 E6. public string[] Split(string[] separator, int count, StringSplitOptions options)
/ Y( A) x2 ~  B
$ p' T# G2 R# a( h代码6 |+ M% a/ E2 y8 H/ B6 [
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素6 c& V. E( \% }9 P' A# S4 Q( L' o
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-30 17:58 , Processed in 4.741884 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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