晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
5 ?; L! w/ Q9 W8 S
3 V+ `+ `7 Z# L% ?读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
5 x6 E( n% G; Y1 m: @; T4 l- x0 X8 e
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别0 Q! k. m/ [7 k
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看% K! i1 N4 Q& A" a2 ?; x; p$ ~# H, ^
http://www.itwis.com/html/net/c/20100506/8234.html6 g/ |. u, t! U! N

  f; z+ b. T8 h  m$ ]程序代码
. m8 i7 S; ~+ j; {0 @1) public string[] Split(params char[] separator)5 w7 v6 ?' b5 k  X( r. [
2) public string[] Split(char[] separator, int count)$ z/ h2 a4 c+ P; Z( `
3) public string[] Split(char[] separator, StringSplitOptions options)1 I- t) ]" F3 ^% D1 C2 H1 D
4) public string[] Split(string[] separator, StringSplitOptions options)/ i- e4 b/ g- x. l. K' q* m
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ G, g3 N1 x) n2 C! g. q6) public string[] Split(string[] separator, int count, StringSplitOptions options)+ t: ~5 }  U, n! C' W, G3 U

3 z7 {8 @: W% L下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
3 j5 M' Q- z# }( x: S. x; ?8 D
  R$ i/ K- Y7 `1. public string[] Split(params char[] separator)- A7 n5 D6 A5 `8 C% i/ D6 M' Q1 U
- q: S$ U0 o! ]8 s8 O8 U! R6 o& g
程序代码
7 g/ M% t9 c( o' zstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}5 _7 z* T8 z$ {& \, z6 C- N
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
, G# g# f' C8 H, l+ e* s6 r$ B
" F% n, v7 c5 B, O2. public string[] Split(char[] separator, int count)
# p  C( r* E' r6 X- p
5 Q* S# Z; }, |7 z) z3 ~+ v; @0 T: ~ 程序代码, X& c6 H7 H2 y( M" p
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}( ?$ u3 Y$ i( O- x2 g
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}* Y0 S  z" C( P0 W& }; b9 M( ]" O
$ \7 a. t0 @+ x6 @2 Y+ m
3. public string[] Split(char[] separator, StringSplitOptions options)$ S- z, h) ?& U

5 _: r  ]& S( O: O6 m 程序代码
5 Y" u# b9 ~4 estring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
8 Y* j, E! x1 C5 |; g: p' qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( _/ a5 |. F& @7 w4 B
6 O6 |5 g0 p* G; k0 f4. public string[] Split(string[] separator, StringSplitOptions options)2 G- C4 ?' H" `2 ]" l; o
4 Y1 \0 [# T  c& ?, n( s
程序代码
$ L7 K5 F7 ?' g! x( {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* Z! D2 m) I6 f+ P& J/ n
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
! V6 w# k/ {6 q" K* x7 f* C) r' J7 ^2 y. I
5. public string[] Split(char[] separator, int count, StringSplitOptions options)2 F* x: b, i& L7 G+ ~

4 D( c6 T; Z& \: I9 c& S0 n+ A 程序代码1 S7 T/ J8 _" h) C8 U* F
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
% N/ \& t# e5 G( c9 K# u! ^% y% _string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 U; A$ o' a. q* Y% }: t" {1 y7 d) \" i. {& C; b' D8 }
6. public string[] Split(string[] separator, int count, StringSplitOptions options): [- R6 \8 w4 o( o$ C4 N
1 C0 j- m3 D( n9 n1 Y, n4 I4 j, ^9 K, t: {
代码2 V, S. m3 a7 M4 L2 |/ E0 h( K
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素- h$ l7 V4 ]: D+ R
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-4 16:26 , Processed in 6.065663 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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