晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
) r+ ~! \' `# H5 P  I2 b6 j
  q& t6 i% A0 [读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码/ u7 o; p* ^# u% F1 p( \" i$ _1 i
( v( r1 i. C+ L8 Z3 o
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别% ~# }- c* i- u  Z4 S* {
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
7 I9 X8 h7 y9 M) @% x* q8 w7 l' N; W. `http://www.itwis.com/html/net/c/20100506/8234.html
& I6 ^8 [# F" O& g1 d
. B+ z5 J  e8 u% }2 M程序代码
0 N3 |4 `2 K0 D8 w6 I1) public string[] Split(params char[] separator)8 Q3 D9 ?1 K  {  k/ r
2) public string[] Split(char[] separator, int count)
* X1 @: D/ [8 l$ W! L- _# l+ g  q3) public string[] Split(char[] separator, StringSplitOptions options): W1 j1 c# u1 D
4) public string[] Split(string[] separator, StringSplitOptions options): S* l9 m0 b& T: Y
5) public string[] Split(char[] separator, int count, StringSplitOptions options). g. }, g+ i# b: T
6) public string[] Split(string[] separator, int count, StringSplitOptions options)
' ~$ Y' J$ F) q5 e4 x4 P- M& H6 D1 q5 l3 B
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
% u. s+ w7 ~2 I  _! j9 b
+ \4 M* [, n6 R# L6 D: o1. public string[] Split(params char[] separator)4 t+ {( S" B; t
' I& m  V7 Y0 z$ b5 z1 }( m) O
程序代码2 u; m0 x8 u$ l  a; N. h
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
1 A" h4 p( [# B4 |6 F8 Qstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
3 V, P# n# g, w, e; {9 U+ j7 C* m& E! D! n$ q  q# t/ w3 a
2. public string[] Split(char[] separator, int count)) c) n) i5 z/ p

0 T/ M; C: I, h( v; ~: B 程序代码
' r2 Y( @1 T% X7 }4 \0 M4 sstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
. Q1 ^- C! F& Mstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
, j4 F& P6 M7 E$ v: k$ ?
! x" U5 G8 G7 W, O" h+ W/ q3. public string[] Split(char[] separator, StringSplitOptions options)5 c$ m4 C: Z5 t) d) j+ B- |

5 T" o3 p5 ?+ w 程序代码
) `: S- `$ X' @/ v0 hstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
; C$ z6 J* x# e$ |+ u6 @3 t  pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: c- Z$ ?: D2 l2 z& g' r
* s) q& }, `/ A$ w" Z! o* p4. public string[] Split(string[] separator, StringSplitOptions options)
* u( F0 R4 @) ]% h+ L, Y/ B& y4 W) [
程序代码
4 t9 G  H6 }% s: G) Z( fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素0 q% n8 ]/ c, T2 d4 ]. G. d' o! b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素- ^/ i9 k& Y0 R8 H9 o

5 R+ x( {5 \5 D, q  B5. public string[] Split(char[] separator, int count, StringSplitOptions options)' X* K2 t6 o. {+ d, m; \
4 N# i) X8 e8 ^) v. W' g: o& l
程序代码
* N, E! g- {. V3 x' Rstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
. O7 |' o# a* ~- q) w0 ~  N* K( _string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
: S) i* Y4 a# G4 Y
2 c# r0 ?3 t* e% ^& M6. public string[] Split(string[] separator, int count, StringSplitOptions options)1 M5 g+ w/ ?# T8 B1 ?. P: ^8 q
# r+ j! b. d. W
代码. P& n2 U- D* X" P1 C
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! s: q/ k8 t, t) ~string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-26 17:27 , Processed in 6.068971 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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