晨鸟科技

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

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

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

8 Y( x2 B1 Z: k( Y4 H读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码$ Z+ `% _  m2 w0 U/ C! h) d
5 I. R5 q0 R& _" Q
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
5 S5 w" ~( D1 \. o9 F) L5 u, Xhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
9 L8 P+ o+ ^- v: Hhttp://www.itwis.com/html/net/c/20100506/8234.html+ B1 M6 j& g( f
8 c2 [, b; f1 [
程序代码0 C. o$ \2 c; e
1) public string[] Split(params char[] separator)
0 ~/ d9 s% ~8 y( d  H7 i; U1 h2) public string[] Split(char[] separator, int count)  p4 u/ \% ]: g" ^4 n- r! c
3) public string[] Split(char[] separator, StringSplitOptions options)
* Q0 z2 y3 U8 w2 U7 {4) public string[] Split(string[] separator, StringSplitOptions options)
1 r) Q3 T+ x( N0 j; o8 h6 }5) public string[] Split(char[] separator, int count, StringSplitOptions options)7 d* s% F- I1 L$ f. W# @/ u
6) public string[] Split(string[] separator, int count, StringSplitOptions options)3 _' s  C+ N5 |7 v$ Q

: O' Y- A+ W) }) D( P下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):5 |) D! s; F* g( P) w& W2 z

% r: _* ?# c  h0 p3 @/ C, @- T. w& k1. public string[] Split(params char[] separator)
( C# m% }( T( W- z  {" W1 i( j
' Q# ~6 L4 s- ^9 @( V% ?$ p+ `* t 程序代码
  T/ z7 x+ J. z' g  t+ kstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
& X$ k* L9 J8 l2 K  M+ lstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}5 |0 ]8 [, t. e* t1 v
3 r- T) d. r  x: ^- _$ x) M
2. public string[] Split(char[] separator, int count)
6 o& H- f. v/ s4 K2 x9 R9 E, n" F/ R. ]. E: d
程序代码; X7 F1 k1 S" N: h/ h
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
7 j5 V4 v$ @* e6 ^0 B# d5 P, Ostring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
8 o( v3 A* |* V5 ]
9 {9 f/ A$ Q( W$ u) N; z2 o3 `3. public string[] Split(char[] separator, StringSplitOptions options)( Z" L7 s- A5 `% N

' A; H6 e' y0 ], ?/ ?- K( X 程序代码) _5 T/ }7 c2 r! K. S
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" |: n/ q5 }) nstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素0 e# n) I; ~: O* X7 ?& ~

4 O7 s2 b* u4 ]  }: E* C( S, n9 |4. public string[] Split(string[] separator, StringSplitOptions options)
2 c! p3 x; d. Y3 E
8 T! {' F: O$ ~, m 程序代码
( h; Q' s! T% jstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
! l/ _+ K* c# e9 Wstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: ]6 r" ^! Z1 `  y3 l0 N- C/ }+ P/ w) T! C1 |; z3 v
5. public string[] Split(char[] separator, int count, StringSplitOptions options)( q0 l" F3 x$ x, `9 Y
0 v; x) c- e& a' y4 S1 I; ]
程序代码1 k2 q) i/ _" W5 J9 x
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素0 A  s# m' {) C
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 S1 ]2 S' G8 S
+ ?0 y) }4 x" T
6. public string[] Split(string[] separator, int count, StringSplitOptions options)2 Q8 ]2 E5 g8 D/ D0 ~! {

) p4 U( j3 u0 M, ?$ {$ s3 b+ U代码* I7 q! c7 h  O* E* t4 h# y9 e2 g
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素7 P: V6 Y' X5 \4 F3 @$ _0 E& s6 x
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-19 23:21 , Processed in 6.063709 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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