晨鸟科技

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

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

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

' `' h: p8 M6 m. g! W# e读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码6 S# ^8 A2 E; s- l& L

0 ?  f) S3 R4 l; j对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
( x! Y' w( [4 i" Z6 }" r7 Jhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
6 i- W6 l& a9 \5 Phttp://www.itwis.com/html/net/c/20100506/8234.html: T2 s1 i+ S' n$ m' c8 M1 |( n

! P/ h- m8 e! e" R! r8 G' n程序代码
3 \* U) q3 F3 F5 g0 L1) public string[] Split(params char[] separator)
$ G/ i" d9 G; y7 L- |- a) m9 `$ C2) public string[] Split(char[] separator, int count)' E$ k/ B, h7 ?5 D: v! y1 n
3) public string[] Split(char[] separator, StringSplitOptions options)
( `% @! s& ^8 D' A" M5 H- f6 `5 H( U4) public string[] Split(string[] separator, StringSplitOptions options)8 `' b* B5 Y! O. i* ?) P4 w, l
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
( F& D4 j( C8 D6) public string[] Split(string[] separator, int count, StringSplitOptions options)* w, u' u" L) L. I. ^& H1 @5 W

" U/ Q$ @% }- ~2 {& p2 H+ j# n下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):$ O' Z- w4 i8 ^  V
6 g8 `( D5 G4 C
1. public string[] Split(params char[] separator)
  V; r5 T/ h# q% n% e* u* c$ O2 ^4 C/ {5 i
程序代码
2 v; b/ J" {/ v' Y+ ]$ n1 H3 nstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
( B8 \' _* J& ?8 pstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}8 B% r  ?0 B" C

$ J/ L/ F( p2 |0 n7 n2. public string[] Split(char[] separator, int count)
- t* Y/ w$ L5 G4 z  X5 P( _: b# [7 I- p' L! p8 Q' D( Y: ^
程序代码- I* h% @# E! v7 t
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}. U; r* k$ ]- w4 ~- `. |  B- J
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
$ e- ~9 [9 a  q5 P! H( ~' D* Q/ {; [! u" b3 q& Z$ N/ J
3. public string[] Split(char[] separator, StringSplitOptions options)$ T0 Q) a) E3 d& M( R! |  Q

) ~8 L6 W0 |) q9 h# y' w$ T 程序代码
* T9 Z4 F5 _' W* T4 d4 I% Z! _# ^# E$ tstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素! b+ b& C, B( P9 @( j( K
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ l' M! @: x# O+ ~0 {# S  q: j

' h8 O$ a! W+ ~% q: l( k, e4. public string[] Split(string[] separator, StringSplitOptions options)/ {& x. n8 f" P* i& a

' {- E5 ~/ Y) H# q* _ 程序代码7 ~( B& \2 J. H( ^/ k" D! I
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素  r, N* |& g+ u  Q$ Z- L6 ?
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! y7 ?3 A0 {5 [( E: B8 y

; w4 j( B! W- h& V5. public string[] Split(char[] separator, int count, StringSplitOptions options)3 h* T# j; n% }3 |7 N) m( Y

/ m/ [& h) Z# I4 Y 程序代码
& L* k& X; C$ w' x5 fstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 S- T! F7 q) n6 f# W0 v$ \string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素7 K/ N9 K' q9 |( D" [4 M: h% g

  `8 ~+ z2 ~% K0 z8 Y4 r. i6. public string[] Split(string[] separator, int count, StringSplitOptions options)
, L9 C8 L) d3 R2 @; u# b, H' X( e* F; i3 f: Z
代码  C+ v. V6 |5 _% ^! _' s7 s
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( `+ N' e2 E9 Q- i( X* Mstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-11 01:00 , Processed in 6.085195 second(s), 15 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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