晨鸟科技

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

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

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

8 N- A1 [$ w( x- }$ {& O7 V读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码' H  A$ L5 i9 T. \& E" j+ w

. G! \6 T7 M1 }  z6 N对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别  P- W. G$ a: _8 |  p  y, S4 E
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
9 ]! t% A3 C( e& p1 i1 m+ _http://www.itwis.com/html/net/c/20100506/8234.html
5 L* k% }; Z7 C6 O2 O
! B- e& B0 Y. q- x! W5 b' i( e程序代码/ W2 _! M+ m4 [6 h
1) public string[] Split(params char[] separator)
. t6 v) f4 ^, H! x6 d2) public string[] Split(char[] separator, int count)
# S1 G. }8 L" H3) public string[] Split(char[] separator, StringSplitOptions options): A# R* B1 C; Z& u+ x9 z( e% H# X
4) public string[] Split(string[] separator, StringSplitOptions options)
5 o. b1 @* S2 p/ a8 {) ^( t5) public string[] Split(char[] separator, int count, StringSplitOptions options)) r+ C" t! C1 I5 @  b+ ^9 @
6) public string[] Split(string[] separator, int count, StringSplitOptions options)" ~7 @6 r* n3 E

  |% r: h% Q& H! |& ?$ E# t下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
. I$ T/ r0 g2 w; a& c: v) h6 S9 r+ O2 ~( g) Q0 W5 B& n( F
1. public string[] Split(params char[] separator); q' \# N) `& y& e
4 U7 o0 {4 n- I; ?! X% j4 W! R# x6 E
程序代码5 }3 k1 G* E4 D
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
; o% S* w' Y( xstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
' q5 _7 |4 h  r$ [! @. Y6 O: ?" Y! y: N. U
2. public string[] Split(char[] separator, int count)( u. e( n) ~( n, Y. O  ?9 p

" {% J& t. d* \$ T( {, n 程序代码9 a  m- Q) [$ W! w5 @1 v
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}1 \% I0 P8 k) l" s
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}0 ~8 x0 B8 y" i0 Y1 K: S5 I8 z! t
7 E- a# \, y; Y9 A7 g1 V
3. public string[] Split(char[] separator, StringSplitOptions options)
$ C/ u( x$ \' O3 d
( @6 \+ I. c" F% d9 y. a( { 程序代码# G1 z1 E; @8 m/ P) q/ b
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素  V4 x+ T* y" v
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素8 R8 z3 w( [9 ^

4 i* k! P1 ?2 ]& q9 a; Y7 |4 U$ t# T4. public string[] Split(string[] separator, StringSplitOptions options)
9 f4 ~% H' t& l, D# F1 p) _- ]( _0 ~4 P' o  M1 A
程序代码
& k1 b! B/ {1 U+ g" @string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
9 t! T( k/ v1 t7 a' W2 u/ m) jstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 Z/ G3 {8 Z0 G$ |) A4 ^
  l: t- ]/ p4 G' f( i5 N- y# e5. public string[] Split(char[] separator, int count, StringSplitOptions options)/ u3 Z# F( E! i8 _& K5 I0 I+ {
4 G) L6 g4 P. @* _8 G5 R3 X6 I
程序代码
2 [/ u9 l5 s  n) Qstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ d( G5 Q2 a; @: Y9 U8 k; astring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素2 x& F3 W, z- k: L1 F9 z' I4 y; L

- F& y) }9 a; ^/ H6. public string[] Split(string[] separator, int count, StringSplitOptions options)$ ?/ a: e/ r! A' @

) I6 l6 W$ j9 K: {7 b# W* T- _代码" p6 Q" F* p( T
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* O0 U9 w, x: v, ]
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-21 21:03 , Processed in 6.062112 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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