晨鸟科技

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

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

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

" `. n8 G' Q; ^$ A+ r* i读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码3 T$ i2 |8 X- d+ t3 _
& f3 Q& {, ~; E+ N9 O
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
% |/ Q0 O$ Z4 ]# R! q* k+ ehttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看$ z' L) O3 E- R$ b  O/ A
http://www.itwis.com/html/net/c/20100506/8234.html6 D+ w% y5 R3 Z' G- E' h
; S  [  I( b2 P
程序代码( T0 P4 a& d/ Y! U
1) public string[] Split(params char[] separator)6 ?, j- M; b( _9 a' {: w3 L/ `
2) public string[] Split(char[] separator, int count)  A/ \) I3 a' x
3) public string[] Split(char[] separator, StringSplitOptions options)6 w% w7 g! D1 g: c
4) public string[] Split(string[] separator, StringSplitOptions options)
- P0 d% ]" J9 H/ c5) public string[] Split(char[] separator, int count, StringSplitOptions options)  @$ [* h8 ?- [& J( V; L
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) V3 W- F- a% j1 z/ b1 A9 y6 C! Q- M$ i5 b% k
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):0 t6 \$ _4 g. |' X* i1 V& i! ]& ~) ]
0 F8 ?& x/ p2 u3 h3 r
1. public string[] Split(params char[] separator)
% V, h: \8 J) Z' j+ R- c0 V+ m5 G8 o2 w' R0 f
程序代码
* U* @4 N. a; K% K# v1 b" |1 p& W# bstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
$ ^5 s! G( y1 T3 [9 W  m0 u: D6 Zstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
9 O+ u$ \. @3 A/ `; b/ W& h/ v0 P1 h1 }/ V0 d) Q
2. public string[] Split(char[] separator, int count)  Y* I+ t8 K% g0 v1 G
- S4 N: e: X6 i  L5 Q
程序代码3 b) ]; C" F9 k' N4 |+ d. a! \
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
5 Z+ r7 S  T# r; o) Kstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
; g) H& [! r4 G' {+ ^. c4 A% L# R& t0 [( U3 J
3. public string[] Split(char[] separator, StringSplitOptions options)( v* f; l( c) n. H* E9 b
( r+ |  Z: X" c( D7 r
程序代码1 |# r9 W  W( h( D4 [; w* @5 h' u
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素2 L6 k4 e8 A6 S3 a+ y& M6 O
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 q( v* L8 J5 [, M2 w% x0 @5 q6 D

' i% H$ Y. l; i- e$ b4. public string[] Split(string[] separator, StringSplitOptions options)
$ |$ ?0 L# P, H$ i0 d: {& {. ~/ C) d  d. Z9 C7 c$ j
程序代码
' K1 j6 d$ I  V* ?) bstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素. ?* Z5 I, D: E; Z" {% r/ Z' r& k
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& Q) m5 i- a( Y, r. h- i

" B' D5 {$ v# g5. public string[] Split(char[] separator, int count, StringSplitOptions options)) `/ E( x7 A) l$ p$ C
3 P. |# s/ w" ^1 L% H7 B3 o* ?
程序代码9 {9 k+ \( C; b, h
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: R  o3 k2 I# xstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
8 @5 y1 v6 u3 f0 }' M
% |( ?' m* O% B2 j5 ]6. public string[] Split(string[] separator, int count, StringSplitOptions options)  F- i) L+ s6 D- R4 m

! c" g6 B2 k, M  ]+ f* _代码6 f3 s; M9 o7 x
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
: M+ V+ L" b/ j4 g6 z! Qstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-2 04:53 , Processed in 6.070901 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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