晨鸟科技

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

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

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

2 [  h1 s+ R8 |, |读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
. E6 K+ W8 A# P, I* H- z/ F# ~1 G3 V$ V
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别' H' w6 N- w8 }- W. P" ?. z! g
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
' n: `  [' r3 \, N0 }( rhttp://www.itwis.com/html/net/c/20100506/8234.html. y4 `. K: j% D! k

9 j' o# r5 l7 O8 W% |1 s$ H程序代码0 M# V9 ?- o% U3 t; s6 e% V: @
1) public string[] Split(params char[] separator)
5 }9 c1 s- u' L+ T6 t. d2) public string[] Split(char[] separator, int count)
, J! l: W0 x. w' f0 Z3) public string[] Split(char[] separator, StringSplitOptions options)
' H/ e) Z) W+ i1 S4) public string[] Split(string[] separator, StringSplitOptions options)
9 n! e2 K/ m/ N8 s5) public string[] Split(char[] separator, int count, StringSplitOptions options)1 [9 r; w( P6 u# f
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
; _6 _7 g' R: R- a5 p4 [- U8 K! g1 A6 o( r1 A
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):6 t4 N: u1 T9 S* m5 @+ J
6 v6 T/ O7 t$ ~
1. public string[] Split(params char[] separator)
# v" n5 u$ c# W; V; Y' N' e! \3 ~# e" Y, i# L3 A
程序代码
" O# x/ K. l# V1 sstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
2 s$ c0 a' b0 V  @2 T. S+ Astring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}7 j9 @  d" [6 S, g8 l+ `. f
3 |, U( Z, q- i. L) `5 n
2. public string[] Split(char[] separator, int count)0 c; }7 F) c6 V$ |1 F

3 }: i' \. D, c 程序代码
2 B  q' K# S! A6 rstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
# c* K. L* ]. |  s% xstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}* }) y; b. \0 L6 G  {
( F: I6 {6 n0 W$ M
3. public string[] Split(char[] separator, StringSplitOptions options)
! V; J! s; P# o- l/ Z: O( R; r) E- b: J) E2 T
程序代码6 u. H1 n6 H$ e+ b- C  R% ]( s
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 w! Y: u. B: K0 m  r  jstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 E( i7 [" k% v" U3 @; t0 o! ]+ O2 g- v* l+ c, c4 q+ ]+ }
4. public string[] Split(string[] separator, StringSplitOptions options)# Y) T1 e9 v" `7 M& N: R

7 R1 I) t8 I2 O 程序代码2 Y$ ^4 b# y, S- f7 ^# Y' l% H$ Q
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
. i6 _# v9 r3 N/ q, Nstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
5 Z: S/ V( l; o# c9 X; M4 {+ k2 T; q
6 x& K' |  a) y7 C, s5. public string[] Split(char[] separator, int count, StringSplitOptions options)
( [; m( n5 b1 o# r; Q1 w3 p
7 P6 x1 _+ e0 |5 L" R 程序代码8 ~+ @- s7 n7 B1 u" [
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
/ [/ |& P0 }+ o1 g; x% A+ t1 Qstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素* p5 q* T. a, X5 d

0 Z9 |* i9 o$ t, z% B6. public string[] Split(string[] separator, int count, StringSplitOptions options)" A5 h5 Q9 r. D) r# V9 F6 r' A
+ V/ Y4 m( B3 ?9 c
代码
+ S, e# S& u% p$ Sstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素: K8 ^5 f( p5 Z2 }/ x* \  r
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-17 04:51 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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