晨鸟科技

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

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

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

/ ?3 N! L+ E; P9 ^0 [: P& ]+ A读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
; G, `" B3 P" b
* X2 N1 e# |/ l对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
7 A* K6 o: `- ^9 lhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看& A5 S. ?7 ?# p$ t+ L6 h
http://www.itwis.com/html/net/c/20100506/8234.html
, A4 `, ^& t- p. N  P( ~
: i& a: ^. L; ?' M! b- x程序代码" ^% F2 K! E0 ^6 j/ C
1) public string[] Split(params char[] separator)
1 J5 c; r1 M( ^, m# v3 h0 |2) public string[] Split(char[] separator, int count)' u. {7 y1 m' a3 K8 y. ]/ h3 w7 j
3) public string[] Split(char[] separator, StringSplitOptions options)& m' `% v& b! x2 K+ j$ n
4) public string[] Split(string[] separator, StringSplitOptions options)
$ Q. ~  \/ T$ G+ s6 u) }. X3 H" V4 o5) public string[] Split(char[] separator, int count, StringSplitOptions options)
6 \1 R* d7 }7 I$ r: K0 Z! R6) public string[] Split(string[] separator, int count, StringSplitOptions options)  Q" h4 I; d$ {& f" ?' o# x
$ n, P- q# @, f
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
  Q7 o# \; s" d8 n& T2 `1 H% F; G  b9 R/ \
1. public string[] Split(params char[] separator)
6 Q0 ~% e) G$ V% D% D# _4 t. ^
程序代码3 F9 ]! G8 @$ ~! c
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
+ G! N  }! G" T7 Y- L1 _) astring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}! k5 n8 ~; ]) ^2 `$ @9 Q

* j5 z" ^0 R% ]: d2. public string[] Split(char[] separator, int count)' Z9 Q% O2 @4 ?6 _  {+ E

. |) a. w  ~5 f8 |; ]4 X" u 程序代码
- o9 V- k* Z" x5 S: a' m- x! M9 Nstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
! B; |2 {1 F& u8 A3 Y5 ~string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
+ n8 G! P+ p  t; z8 D% r- y$ g! c7 ?, m% g% Q4 Z2 l
3. public string[] Split(char[] separator, StringSplitOptions options)$ t9 t: Q0 P. Q, y9 @/ B1 l& S  c# M
: G; m+ D% [$ G" \# X
程序代码8 R& X+ P1 ^+ ?: q, ]
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素( H8 ?4 i! j$ D2 o* Y
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素. _. Z  T9 d* p
, m7 k4 z8 m8 V9 M2 {: m/ d8 q  a
4. public string[] Split(string[] separator, StringSplitOptions options)
) Q( s$ U! }  f. V3 a; H8 C3 i( P$ N: [9 i+ i2 {4 t; `
程序代码" D  j  V* J1 z( Z/ ]
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素' |- z: W3 h; x1 G4 W
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( P. o8 O9 T& F5 v
1 s" R* `1 `# Y6 e5. public string[] Split(char[] separator, int count, StringSplitOptions options)
7 v, q' N/ @, r6 J* m$ `4 a3 R; E: F% w! b! p
程序代码: e; |  I# c( m$ @' N4 x2 P
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
5 U- Q8 W" V9 i& b% kstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 c0 [' L8 r9 ^9 T# {( V% e* Y0 F% s* u& d3 ^- _
6. public string[] Split(string[] separator, int count, StringSplitOptions options)/ x. Z6 b+ M8 a8 l+ ?

* X4 @- Z3 O" `6 J2 _代码& i1 f& x+ E1 f0 U
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( [. K0 N+ A$ d* V, `0 b( q
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-27 16:52 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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