晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
( b: x, h0 t$ I, r* D$ P+ ]3 l* c; q
  T7 ^& {6 j  y. a读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码2 [- ^+ X# A$ k

% X+ @, S! N& H7 J对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别7 s% ^  |- R' H% h& i7 ]. [
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
$ f: w8 O+ i) v" a5 Fhttp://www.itwis.com/html/net/c/20100506/8234.html
& w7 O8 A0 w2 u1 L0 ^5 C! ]5 T1 V+ L$ [
程序代码
$ R8 f" Q2 i7 g/ {6 }1) public string[] Split(params char[] separator)0 \) }0 O; f! y
2) public string[] Split(char[] separator, int count), O6 J$ ?' q4 V8 b0 z4 f
3) public string[] Split(char[] separator, StringSplitOptions options)' r" w" z/ [4 ?) W# r2 i4 X6 B8 x
4) public string[] Split(string[] separator, StringSplitOptions options)7 u. G4 G, ?# H* f: O4 k! u
5) public string[] Split(char[] separator, int count, StringSplitOptions options)  [" w& s3 f8 n& X  V3 F2 f
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
" v7 [3 R9 B' Z8 k0 x
$ x* X2 ]! ?# G) l8 p下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):# r9 ?5 c& c  V' H  P7 q' ~. w
% h  o: _5 ~1 E! ]" o. J
1. public string[] Split(params char[] separator)2 Z& F3 P2 _1 r! Q2 Q9 t8 x( u8 t8 ]
2 C) D4 @) n+ K  B) m8 T1 ~! g$ f
程序代码
$ ?! b& X6 \. {+ t! q0 Z3 tstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
4 L* h# g/ O. Q; j, K5 ^string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
9 U+ [# h! k5 D& `0 v3 G7 g6 o+ d
2. public string[] Split(char[] separator, int count)
2 B; O5 @/ i6 [8 p- G# n. T( h% z  T& G1 n3 [3 _. ^
程序代码. }& g, S2 n. A* [  U) q# u
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
1 l7 i; p' ~( t7 Q) cstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}# M  V# y9 V5 ~

$ @4 s1 L- N. s3. public string[] Split(char[] separator, StringSplitOptions options)6 K2 s5 j" {, s6 H' ?2 D

+ V% t/ x2 H5 L0 K 程序代码( U& {, K! `: k, F6 T
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
# z- R! Y: E! _1 ?6 x4 Ustring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* \" E7 Q& ~- A, e* s
' Q1 R! {8 H+ G' W4. public string[] Split(string[] separator, StringSplitOptions options)0 h$ j+ n3 W: I
0 Q2 |3 E6 T$ q! U5 a5 _& D
程序代码
0 ^; Z5 D0 l8 }7 H# l/ ^0 \string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" ~/ R- ~4 k1 p- h/ e5 z8 A0 ]string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素% t" j* a* R7 c# f

1 e! M0 }/ y- M* z5. public string[] Split(char[] separator, int count, StringSplitOptions options)$ v* ^7 Y' x4 H# T

6 @& U# W7 b% E( h& M+ f$ Z/ G 程序代码/ G% o  b& Z' E5 E5 V8 b. O
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素3 b7 g1 Z8 d* G9 d" {( j$ W* ^7 B
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
/ [- @  X/ M+ K/ X( A5 o+ H- R
. d3 H, S4 ^1 F5 t/ x. `6. public string[] Split(string[] separator, int count, StringSplitOptions options)2 B: w' K  l4 P% \* _% U0 _
5 u4 u) b- {/ }3 Y1 @; b* `
代码' k  @5 N2 H+ w. G) S
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素5 E2 w9 Q4 N  b, n0 h
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-3 02:37 , Processed in 6.069924 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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