晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件5 Q! C2 ]  Z4 T7 o: K7 `" W- o
4 C3 N& o2 l" X/ o( |
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码2 S: T/ ?( D8 P. H. G
: A# @8 o) J+ Y& E& c6 J) \9 y+ g
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别% q2 O/ ^/ D: i. \
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 Z( C- H0 ~: b1 a' e8 E* N, y: lhttp://www.itwis.com/html/net/c/20100506/8234.html3 s! k+ |- k# b+ u) @
+ q2 b8 {; s! }4 q- O) h
程序代码( F( F; b- i4 t
1) public string[] Split(params char[] separator)
+ v. t5 O" q2 p. |3 o" n7 b/ F) h2) public string[] Split(char[] separator, int count)
2 g3 S3 R0 K2 B# \. ]3) public string[] Split(char[] separator, StringSplitOptions options)0 l( J, S) n$ t: X$ }& a3 v% q
4) public string[] Split(string[] separator, StringSplitOptions options)+ N( b$ _/ g+ i- g: K0 Q. j
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
9 ^! a1 a% g3 ]1 W# X* D/ O6) public string[] Split(string[] separator, int count, StringSplitOptions options)) ~* Z# o/ E. n! _3 q1 ]
, u2 R+ z) p& s3 n- ^' Z
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* c  ]. B0 k8 f* [% W; i8 W: o
, J, l/ d3 _4 m! v# R  {3 Z
1. public string[] Split(params char[] separator)! j; s; K- c$ Y1 }4 M

- A) G5 L7 V# F2 c! X; n 程序代码/ k! C3 r4 I" s* J4 Z
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}$ F, q0 s/ g! T; m
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
1 v0 t; t2 Z/ o0 h5 w
4 f& _3 h+ }9 J# t# q% b, w9 E2. public string[] Split(char[] separator, int count)% @: \+ X3 T+ F$ c2 f6 ?( e3 v  @
, Y% q9 r4 H0 {0 T8 x$ r+ ]
程序代码
4 i1 P% W7 x7 y8 y) Pstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
7 `& X7 I8 q7 hstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
; x, A9 X4 x& \3 h1 @
+ k- M% K' Y4 f$ r3. public string[] Split(char[] separator, StringSplitOptions options)  f. Y, y2 I6 y7 C
% N. x+ x/ o5 T8 w% Z
程序代码
( ^' M2 z( M* U) qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素9 ?& N0 V- R6 x# m
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素# p# o# Y# Y1 s

. \6 o) O$ ^7 ?4. public string[] Split(string[] separator, StringSplitOptions options)
: {5 y) x1 R; I6 W5 U! _- |! T9 U& O7 c0 R/ |; F: ~
程序代码
4 h9 O0 s( ?5 @8 `string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
/ E( w. l4 j  m; \string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
) I) C: A# Q% d2 C' n) I
5 e" ]) G+ p# c, r9 {5. public string[] Split(char[] separator, int count, StringSplitOptions options)
) i4 f3 T. w/ I: l7 J- l0 T
6 O2 \% R5 A7 u& K 程序代码
- {6 a" J+ T7 {+ m* J, Hstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素& O- b. L* W; t3 y8 d! ]( {  u
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  N3 U# P/ D7 z9 s. v! s3 {) X$ s4 @+ R2 I' J0 F
6. public string[] Split(string[] separator, int count, StringSplitOptions options)3 r" o! z* p. b$ G. j9 G
8 _; z7 x. g: x; O1 x' |2 D& ?* x
代码  r2 n/ ]' L5 x6 F* r7 L8 `
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 C# u4 `7 m# k4 ~& _1 I
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-5 19:50 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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