晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件9 U9 o; s! _1 v& `: z
9 X4 J4 M& g8 Z. B
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码. I. i+ B3 h0 W. m0 q+ u, Q$ r* {
; R7 a- |# ^' z- ^1 g7 H5 L  X  s
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别+ h& m3 S+ Q! M+ l- N2 |9 V- ~( u( ^
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看7 ^  m3 b; B0 E$ @
http://www.itwis.com/html/net/c/20100506/8234.html
& c9 @$ ]- e) f$ `0 ^5 s7 {! h6 M' S9 }+ v
程序代码
; n, N3 e4 V# q+ T4 Q1) public string[] Split(params char[] separator)1 q6 Q# I: m7 L
2) public string[] Split(char[] separator, int count). Y. T1 N% i% g" o$ @" z, w( ~" U
3) public string[] Split(char[] separator, StringSplitOptions options)
9 X1 e# f1 p$ G, N' }% l' v4) public string[] Split(string[] separator, StringSplitOptions options), S: Q0 U" _( v) P
5) public string[] Split(char[] separator, int count, StringSplitOptions options)7 M# V7 }3 Y7 Q: J, P- s* V
6) public string[] Split(string[] separator, int count, StringSplitOptions options)- d2 i8 }; Z3 y2 ^. l' l
2 i' ?& A# K; l2 ~# x
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):; n8 N$ Z1 K& @9 Y
4 v  g! n( O- P7 w
1. public string[] Split(params char[] separator)8 v+ z. T) n8 b5 W4 K! {
8 [$ u+ W6 e' ?$ F' W- Q' ]
程序代码, {' u. I- \) ], {) ?
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}. J5 ~8 I5 j; O3 c& [/ U# L4 ~& }
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}) r, a6 I" u$ d. u# T( L- A
: x  g1 F5 G' C$ ~. `* }/ j
2. public string[] Split(char[] separator, int count)
# Z0 x! @$ Y- J$ L! t
4 s4 c9 l0 \  `0 d 程序代码
4 L2 B: y1 c9 X( T7 J7 O! bstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}; s& I' u3 N7 V9 y4 o" B
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
7 X, l( V0 {8 l1 q/ S. s* e9 E3 d( L- h: a" q+ ?8 V
3. public string[] Split(char[] separator, StringSplitOptions options)1 Z5 d' L) Z/ C8 x* L+ B
0 v9 Y/ E7 Z0 n7 {$ h
程序代码' e. f# |2 y( C, e# j, X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
7 F7 p! G( I. b6 G/ V9 Qstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素( _# P8 M4 M' J# S; H7 P
) }* \* _% l/ v5 R' h) s' z
4. public string[] Split(string[] separator, StringSplitOptions options)
5 r7 p- ^) B& Z; p9 t/ t! `% I: e4 y1 s3 `9 \, T" v/ t' k+ U
程序代码8 e! t  m9 N0 P' F  r( h
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素/ }! C/ B! I/ z! {2 j$ M
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, I9 R1 D8 C" e4 v( L
& \7 G2 S1 O- O9 L2 O- }- c. T* |# `# K1 p
5. public string[] Split(char[] separator, int count, StringSplitOptions options)9 r% t( l$ X  ~# ~! j/ `( Z  e& d

) j  U* g+ E; S 程序代码
1 [4 }7 C, i9 ?. x- q$ sstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 Q6 ]1 j4 B1 H) Gstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* Y2 ]7 Y0 N: D% i; K: D$ h6 a* {
! E  J- ^$ |9 ^+ K0 q" N" r# n1 \6. public string[] Split(string[] separator, int count, StringSplitOptions options)
! i* V" _! L9 r- q: w! X
' \% k) I* j- N" l! v- u代码' @4 r4 _; e- P  _
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素; d7 o0 g8 {1 U: J0 ~
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-28 07:10 , Processed in 6.066018 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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