晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
  `  v1 r  g/ ?4 F* s9 n3 _, \) m
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
! ?, W1 `1 |  D. o
9 I8 u  `$ ^( D  H- N) Q' u) y, s' ]对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别: d" k; i" H" }) l$ ?
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
8 z% Q; U; i/ L) [. P: Whttp://www.itwis.com/html/net/c/20100506/8234.html- i9 C, z6 U! h

; j( R4 D* ~9 }! \. f. u程序代码
5 E" W" j2 a( M( N6 g  E1) public string[] Split(params char[] separator)
9 X% @8 ?7 C" k$ G: f6 y: W1 J3 y2) public string[] Split(char[] separator, int count)3 Z2 Q& _1 N! S2 _  J
3) public string[] Split(char[] separator, StringSplitOptions options)
! M5 I: [1 Y  [/ a) W. p. P4) public string[] Split(string[] separator, StringSplitOptions options)
1 o2 Q9 W- Q7 A: \) Q5) public string[] Split(char[] separator, int count, StringSplitOptions options)
1 W7 @" I1 Y2 e9 [1 i% }& i# Y6) public string[] Split(string[] separator, int count, StringSplitOptions options)
( w, L" N: Y6 K' p- l1 d. ]2 }9 u& J0 M
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* W* w5 P( T$ ]! p
/ |" B: W2 a  U3 @8 S
1. public string[] Split(params char[] separator)  W2 k' K* A& S- `
) N9 n$ ~/ \$ E' q: R+ v/ W( h0 h2 [6 w
程序代码
9 |; Y+ B  m! F( `string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}2 v' i0 Y2 R3 J/ D' k
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}* Z6 c" d8 t+ w7 Y

; n1 G( V& @( @; p* E4 w2. public string[] Split(char[] separator, int count)
4 D: f9 D; k7 P- M, P
' E; U) \4 ^+ G! }' F+ j8 m 程序代码
  w4 |7 r% C# }2 ?8 a3 qstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}" O9 }0 p0 i7 _
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}3 h+ d6 \$ D$ ]' c. T% O; o
; D' |$ M1 o" N! m, i0 {: F
3. public string[] Split(char[] separator, StringSplitOptions options)
  U# P( H0 y' Q0 {4 W' f& L+ P+ y  p' e/ q
程序代码; ^* D7 U) j% k/ O8 C
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& N, ?: @% P( X( Jstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素, I& X% R4 E' a9 _

/ O: z8 v4 |+ Y2 F7 ?1 z2 g4. public string[] Split(string[] separator, StringSplitOptions options)2 i& D2 E4 W2 h# T5 ~- q/ C0 g  @

8 H3 y& S* k2 q5 | 程序代码5 e" U% |: ?4 _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素/ [: a. P8 e! V9 M5 t, o
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" N- u4 o$ O$ b$ r8 W1 F& o

; y$ A+ ?- c$ t2 d% e" r5. public string[] Split(char[] separator, int count, StringSplitOptions options)
; F) _" M9 |7 S# n  W$ N$ @$ W7 A. Z1 ~  P/ M2 z
程序代码) u9 F1 q% y9 h5 K) v
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
  T/ [& j- _1 b( |string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
+ L; I7 S/ ]! x8 W$ ~5 W7 Q7 T: o
1 Z# z4 c! T0 H% A6 ]6. public string[] Split(string[] separator, int count, StringSplitOptions options)
# E8 C5 ^+ b; C  [3 H; v2 L  O; i3 K1 I
代码& k" z2 ?2 O# L2 P- x: B4 V' d
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素1 n. t/ d' |3 j/ Q! W
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-3 05:13 , Processed in 4.684750 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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