晨鸟科技

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

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

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

. p0 C* U' Q9 D6 L% y% G$ R, s读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
" n% b; N7 C& J
' F- W3 l& D2 b- H, G! a; A6 z对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
, q- P$ C% K  }. O: ~. Dhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
# G% g2 c9 W; }) J" khttp://www.itwis.com/html/net/c/20100506/8234.html
: k! ?  N- Q: p9 p$ d. k: Y; t. B+ }$ e' c  m- n# v1 h2 ^
程序代码9 D, Q7 p  g* E
1) public string[] Split(params char[] separator)
6 B5 H( W; V+ C! b# g2) public string[] Split(char[] separator, int count)
3 p6 w! O+ y4 _' B1 }7 P* P/ E% b5 y" i3) public string[] Split(char[] separator, StringSplitOptions options)& }5 `4 x- ]* g
4) public string[] Split(string[] separator, StringSplitOptions options)
4 T8 y1 x  P* N; M5 F/ x/ a1 {5) public string[] Split(char[] separator, int count, StringSplitOptions options)
8 R+ n- p0 n8 g- `6) public string[] Split(string[] separator, int count, StringSplitOptions options)
) [6 q* p" R( m8 u$ Q
" X* m% w0 ^: C# h7 ?4 v7 F下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
' A+ {9 M8 d, e
, n* b$ [: o+ v1. public string[] Split(params char[] separator)/ s2 A% a& u: v0 `" n& c
2 r3 ?3 F/ k. j
程序代码
8 h% {5 \. P4 N# _- S7 I/ ~string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}: a& d( L/ e! g8 L7 \0 y' j
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}  r& s3 H6 i2 M* }6 d( p9 y8 D4 H! z

; F( L7 k0 n5 E- A7 m! U2. public string[] Split(char[] separator, int count)- D( C( g9 q% H' Q) w. O+ \( B

8 e# e5 i4 b! {! I. A8 G+ J 程序代码
! R4 p- [$ \# Z8 l. m8 G3 }string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}# y& @8 O9 t3 |. x
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}, P% b8 x: i: q% `

1 o& m2 z$ h0 v- r/ U3. public string[] Split(char[] separator, StringSplitOptions options), ]9 f7 w% S8 X9 S$ R# y6 U
4 `, B. m" h  }7 ?- [
程序代码7 z- J; G/ V) A" s, m  U5 K
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素6 c! x6 g' Q; q$ N
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" O7 u$ W9 i9 ]/ M
2 o2 D5 u2 U  B
4. public string[] Split(string[] separator, StringSplitOptions options)' E5 k: V; L" R$ w, Q
( ]8 T9 C) Y( u7 |( z5 r# v& Q; D* O
程序代码
# \4 B( a7 o7 {+ v6 A0 B3 xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, y4 \) I" n7 H9 ]7 _
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- A4 A3 w8 R) Q6 B
- m! C7 `0 W3 `8 `; U+ w
5. public string[] Split(char[] separator, int count, StringSplitOptions options)6 R& A* W6 I6 S
' i+ w) t  }1 V
程序代码
  K# H! b2 c& _5 M$ m% xstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素; G. s8 q8 b# S" ~: Q+ \
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素! h" H, ~! s0 p7 {5 j% b

( v& ]3 u: F4 R: c- @& S+ s7 P& @6. public string[] Split(string[] separator, int count, StringSplitOptions options)8 Q0 @$ t' Y4 B, M
  ?, P# x' {: }& C- w
代码
% f5 @: ?' O& w, ~& p* ustring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素' x1 Z' b# j' G3 @+ o  q; K
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-25 14:57 , Processed in 6.065042 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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