晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件2 F6 O7 b6 w6 L) p
3 `1 S! @: g- V, e9 |. p  J2 r- P
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码% E! M2 g, B% D3 T; P
; ~4 Y2 d! D: N: r* a
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别' l- ~; Q/ o5 J4 i; ~" l" {. f# \5 E
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看! |& S  I3 C: \9 t
http://www.itwis.com/html/net/c/20100506/8234.html
) e7 s' n( Q) m3 M! I4 @% U$ `3 f7 Y# w" t
程序代码6 b+ O/ X, r$ d( X7 D
1) public string[] Split(params char[] separator); }5 Y! z$ z# d- E
2) public string[] Split(char[] separator, int count). T* a9 X5 U0 C7 F( ~: ~
3) public string[] Split(char[] separator, StringSplitOptions options)
# d5 Z/ z3 M- k5 o1 }. B4) public string[] Split(string[] separator, StringSplitOptions options)0 p/ H2 ]& S& @- p8 x
5) public string[] Split(char[] separator, int count, StringSplitOptions options)$ a; ]  ^) z" ?! D
6) public string[] Split(string[] separator, int count, StringSplitOptions options), E$ N: H+ q$ i: x2 q6 c; \2 w$ ]

8 f2 [  @$ C- k. G. f下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):' x8 Z6 `* E: \8 S7 E
# T3 x% t: q- w' R7 r
1. public string[] Split(params char[] separator)
0 n" T# R- o8 V' F  G8 \/ W- V1 z' H3 m( X2 ^# e& H
程序代码
; `' z  O) ~+ bstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}; O" p; Y% g0 [) ~
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}& a( z5 W& T1 C$ n$ n

7 w6 d# V( g4 ^2. public string[] Split(char[] separator, int count)
/ T- |6 v  X/ x3 q& m4 Z9 i! u  l. x( L! F2 |
程序代码+ ^- S- d  U$ Y0 m& r/ U/ i/ A& b7 N
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
: k, Q# o* V2 }. ^  N% U. nstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}, m, E  w! ^1 r8 b3 a) Z
1 h; |: ^  I8 }0 T( y9 U' f; q' s4 M
3. public string[] Split(char[] separator, StringSplitOptions options)
! p  \; X( G* R
" c& f; p4 B' x9 C 程序代码( a" g" ^+ a% ?4 E8 J7 S" q7 ^3 Q
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素0 K! B5 y, N+ g
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素6 e1 o5 L  V, p% F* D$ m* M
& a* S" B9 I. h7 i2 c
4. public string[] Split(string[] separator, StringSplitOptions options)" L  q2 M( u& x, a: z, X

! k) n2 C  [+ V 程序代码
# R/ R. j! P0 S7 ?/ w" ~. \string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素5 {1 R/ j7 t" ^& }$ o% s/ e+ W
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素( X' J- b- g0 e0 k; P. H$ a

2 C8 L5 a: u0 N5. public string[] Split(char[] separator, int count, StringSplitOptions options)
/ A( {% ~, Y: H) Y
3 [/ ]* y$ t: R 程序代码7 T; ]. `# r( U; S  h
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
' t4 L3 Y& ~0 j. gstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
9 Y; B$ ]7 m* Q2 L4 s% V
6 W; y; \( S( @; i1 H) n6. public string[] Split(string[] separator, int count, StringSplitOptions options)
1 K$ M1 L7 P0 m4 N( m6 u2 `" f& P+ W' ~" W$ l- D3 T, G
代码
6 p  d$ J! A0 W; G# G# Tstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
( p$ b0 A  H+ |string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-12 12:39 , Processed in 6.068592 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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