晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
6 x; P6 o) E8 @; L. O4 c
, e9 f% w' l  o$ w5 m+ F# N% |读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码; R( c1 m6 C, Q" ?
- _7 U5 u/ Z8 X! h% D
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
2 ^1 e8 C# p; ?1 w* D9 Vhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
5 E' A0 U; V6 B( O& o8 nhttp://www.itwis.com/html/net/c/20100506/8234.html: m0 a: |- J, E8 S, d7 L

* k( L4 o1 D0 ?" i& I9 S9 v程序代码' O* f9 H, m5 v  _, P
1) public string[] Split(params char[] separator)
% D* L' W0 @. K# w. x) Y6 r( O2) public string[] Split(char[] separator, int count)  e! v" j- }) M
3) public string[] Split(char[] separator, StringSplitOptions options)
: |, w" f3 r# r4) public string[] Split(string[] separator, StringSplitOptions options)) D& b$ V6 e9 F4 i! w
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
) ^9 w; W! B) q8 O( y) n5 C$ ~6) public string[] Split(string[] separator, int count, StringSplitOptions options)
! }( |# Y- H: J' ^; {. }
, Q" b0 {/ n! \8 ?& S下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* i; m! T$ G* z4 e
6 _, G2 A( f6 ~
1. public string[] Split(params char[] separator)) i( T/ A' s$ p$ j5 q5 w( N% @
% i' f4 g3 M; H' b
程序代码
& a1 S8 K) @" S, i8 Ystring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
; w6 H% j5 r$ @$ B6 cstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
' l. S, {- r. K6 ?5 {  t" U* G# U* |& K) P* s- Y
2. public string[] Split(char[] separator, int count): w* A6 b( z/ X% f; N* {( }- ^
7 T7 ]; s+ p7 e- S- d
程序代码
9 V9 C% D0 ~9 \6 Y) {, Ustring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
. |8 f5 w$ ?* a; O2 B, Ostring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
( {, i( M& T$ R0 N# y/ V# @
9 [$ W- f! t" h/ u+ ]0 H3 m3. public string[] Split(char[] separator, StringSplitOptions options)
% \+ Z/ h7 G% H9 C' q4 N0 Q* m/ l
程序代码
0 x2 F4 X, [$ ystring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; x6 W. u/ N, {2 C: b& ~string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
; l" y9 r: F+ r. M7 X( h7 I' H$ s/ T
4. public string[] Split(string[] separator, StringSplitOptions options)* U& m! r4 \. c. @  e% p$ h# }8 g0 T- l
6 T6 F1 u8 F5 _
程序代码& q" ~1 ]% v6 i! Z) Z1 U/ o2 m
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素+ q0 Z* v/ Y9 @9 r! s: S
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 J7 m4 J( v- _% A% y' h8 {2 O: q) G  X: G6 r% X6 K" n2 p
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
4 M  z3 c3 C% J5 l/ o
- b; m" U% o: T6 E  M 程序代码
# o) A6 h- e9 x+ y, c0 @6 Rstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 K" q# d' P  C) U" G" v+ m6 J
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
  A8 a3 }, [# v" b# @+ [' y/ q" X7 X$ o+ x% i- b- }
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
- y5 ?7 M  V7 L0 I% {, m
- p; ~8 o6 x/ W% ?. ^+ N/ `代码; w5 Y9 W* k& v7 @$ x" z5 e5 M
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
4 L5 N  L9 y: m* ^! wstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-20 21:01 , Processed in 6.064065 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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