晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
  N2 p& _. K- e9 u- j
$ M/ N4 B) x% v读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
7 u2 n5 K. w4 R4 O1 a4 _3 V$ @
7 g/ F" |' L3 C$ a& [" H+ t+ Z对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
7 I: x) t. A+ F. ~" uhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看8 U8 X! T# [! Z( p7 ^1 n" p
http://www.itwis.com/html/net/c/20100506/8234.html
7 ~! n3 Z8 F) w9 C3 z8 ]" z4 H8 ^# @% i4 w
程序代码% \0 F5 A$ k) m( ^8 o- c
1) public string[] Split(params char[] separator)6 f: y; X: S, K, G3 H1 e
2) public string[] Split(char[] separator, int count)8 |- H  \2 d( L2 R( M6 H9 D# z
3) public string[] Split(char[] separator, StringSplitOptions options)$ O/ v) J+ @" V7 C
4) public string[] Split(string[] separator, StringSplitOptions options)" {1 K6 Q) j" v/ E1 H% w
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
9 }3 f$ p! T" G" j$ }6) public string[] Split(string[] separator, int count, StringSplitOptions options)
7 _( m$ h. {4 n5 H/ M( N
8 i/ n6 f$ X- I8 U* p下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
: u. O! y3 E) u6 m  n1 p% s! F# A5 c) ~
1. public string[] Split(params char[] separator)$ X" h0 l4 S* M% L: w8 |
  n' }7 n: G- F  `% P5 i  h
程序代码0 o# Y% r8 Y- |8 B  H
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
0 M* G) k( Y& vstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}) n+ G( K# B- Z0 n" Q2 ^
' l1 |8 z; q3 w3 S) X- D6 _
2. public string[] Split(char[] separator, int count). a: i5 I" D: S: g
/ I; n8 d& F6 F
程序代码9 n! L& Y: ]  `* K+ u
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
0 b( Q0 U; G' ~: w3 n$ i- vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}7 O+ d# G: Y' [8 E

! E5 ~5 J" b' U& d3 L+ b3. public string[] Split(char[] separator, StringSplitOptions options)% j8 v$ P5 D: b% \. M- |

! O4 \& W8 m# W. L0 S' r 程序代码
# N4 e) [) ^4 n" L% i6 z( P% H5 Tstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; v# t; e' v$ o" R! U# _string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素$ O3 m! @& e5 R$ {* G; c, L
# \2 i$ l' P. ~7 v$ w
4. public string[] Split(string[] separator, StringSplitOptions options)
+ ]8 [6 y/ O# O# m6 F* s* [
; C( t$ ~* s5 P- c 程序代码
; {+ J. n4 R" S5 y2 B* q1 h% ?string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; u5 G0 H  o: w
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
, V* ?1 f" R2 d6 z* b- e, g
" d% s. p9 [% q7 T" P) z8 `5. public string[] Split(char[] separator, int count, StringSplitOptions options)' d' ]1 J) p: @* @0 N

8 U$ Y4 S3 b3 j' h. y 程序代码
/ W+ F0 l' ]* Z$ g. ]  [9 a0 kstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
  Q! U% b7 y$ |2 j6 Y1 Zstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 d, Y, F1 c  W" m3 N. e: B5 z7 U

% c3 \( J6 m, e/ k( Y/ K; v0 a3 k6. public string[] Split(string[] separator, int count, StringSplitOptions options)
+ ?, [1 \8 L2 P3 Z+ B2 t+ Z7 g) P8 `: a6 ?/ S' n$ I
代码& w7 D3 }! ~9 r$ w# A
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
' n1 \2 W2 B5 w) n* ]/ istring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-26 13:13 , Processed in 4.140784 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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