晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件- P2 a7 L) ]! n& v6 M' K
( C: Q) ^1 m4 M! I
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码- T: z& b% O0 e: D6 J- a8 b

& \+ ~0 ?: ]& l对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
- a: `6 \* U' ]( Rhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
4 ^3 ~/ z) A; U" x9 Yhttp://www.itwis.com/html/net/c/20100506/8234.html( ]! \: s5 s: S- z; L

$ M( c( b+ Y# Y. U9 {6 V, ?" w4 h0 R程序代码
/ g9 q: [: l* J/ r/ ^& g1) public string[] Split(params char[] separator)
, {. p% }0 r% R" t# n/ A' Y/ O2) public string[] Split(char[] separator, int count)
! ]0 L4 p- o% M( {3 g0 W3) public string[] Split(char[] separator, StringSplitOptions options)3 X6 i8 h- E% w5 D
4) public string[] Split(string[] separator, StringSplitOptions options)
% v: |* \# @9 v. L( L7 j+ u5) public string[] Split(char[] separator, int count, StringSplitOptions options)
8 Z( }5 Z* T: P7 e* f7 {# L3 H* q6) public string[] Split(string[] separator, int count, StringSplitOptions options)7 ?. v  B+ O' ~- ^$ a- {
+ l0 {# {3 Q# v* i
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
% c' b4 l) U+ E. d% D
& m* D  p6 c- c5 X- o4 W1. public string[] Split(params char[] separator)8 O4 j3 }# l$ ~' \1 ]& S; [

# U2 b+ A4 w! x7 w* ~ 程序代码6 V8 L6 H( {: q. S( q6 p
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}* c; x* E2 a( X
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}* c7 F' C9 B0 X  Y

2 Z# i0 G0 Y) X2. public string[] Split(char[] separator, int count)
, `" H1 F% X# o3 ^3 w/ \( }& ^9 }9 D2 C7 H4 V/ S
程序代码
1 r- V1 v" b, p. Rstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}+ S2 A9 R, c* C  P5 P8 [
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
1 r0 ^) M/ B2 U# y1 a8 K$ S; S0 W3 D
3. public string[] Split(char[] separator, StringSplitOptions options)2 m( Z7 k, o" j6 h' E1 z
# r; \' c$ z( o/ c4 J% ?
程序代码& K4 t7 `+ \' i# X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
  d+ L/ [% t0 a' ^" {string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
6 l/ N' ^$ \2 I( ?0 A7 f1 Q% g. F$ e
' L2 {, w! j# {8 Y. m; Q4. public string[] Split(string[] separator, StringSplitOptions options)
( T* Z0 l0 |6 T" `4 R& ]
$ D# K3 y( K0 n" l* c3 e7 {, ~, E3 a) J 程序代码
, \; `4 I4 Z" F! |9 R3 Astring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
( D1 X+ @3 ~+ H- Kstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
1 H2 o& F5 C: v) P" ]
& R: ~1 p) t& L" P8 h5. public string[] Split(char[] separator, int count, StringSplitOptions options)
0 |0 d. V) S( L0 C$ [# s7 g5 j, q9 m% M8 W
程序代码8 j! h2 g( j) t) m" ^# F
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素6 ]8 a8 |- |6 m6 U3 U$ E( W
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' H/ T0 I3 e! b* t/ i7 @& t

; R% K/ ^' |5 X6 `0 X6 u+ V6. public string[] Split(string[] separator, int count, StringSplitOptions options)% Y9 b: o$ z* h( Z! M8 u
) W" B$ Y, P* G) M, K0 g
代码
* G3 L/ U# T: T, D% z+ Jstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素6 v+ a& ~) w& ?- ]! S
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-14 09:18 , Processed in 6.069569 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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