晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
8 H. X5 x2 C+ c) G: e
* w. r- N7 f& W& h! u! z  `* f读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
% z7 A. ?* |# V* u" T; I6 H5 W# W
0 s* Z4 b* V) [2 k8 G# K! T) T对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
8 W( p, c7 n4 `, Z8 Ahttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看& \: [* @: w; v0 X2 q7 i0 I+ H
http://www.itwis.com/html/net/c/20100506/8234.html
- y! v! H2 {# \" ~+ ~7 o
/ V! Z$ ]( \- q; }2 y程序代码
' |  `# O5 Z: F) {7 v1) public string[] Split(params char[] separator)2 v  O. u7 D" |8 m1 e) k' Z! ]
2) public string[] Split(char[] separator, int count)6 b2 S" u4 j- G2 I
3) public string[] Split(char[] separator, StringSplitOptions options). N8 v7 J( e7 ?! v  l
4) public string[] Split(string[] separator, StringSplitOptions options)
5 g# k5 _: R. [) I4 N5 _8 ~% X5) public string[] Split(char[] separator, int count, StringSplitOptions options)
6 K; Y6 w& Y- G% ~* m6) public string[] Split(string[] separator, int count, StringSplitOptions options)7 v2 U1 n. i: R5 ~2 ]0 ]3 j

$ J. V- Z  I& q) E$ h2 u+ D下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
- e, I% n% Z) l) @' X# C" H' }0 ]  v$ D* h# K
1. public string[] Split(params char[] separator)* K, Y% U# G. j& |# ?  l

8 f+ J. X8 [( H, u* } 程序代码- T% r, @2 s" [( R
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
5 r4 b- {7 V$ Z6 T0 Zstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}( J& g8 o$ S! Y/ W6 Y
4 X# z. q5 ~0 [$ ]( m
2. public string[] Split(char[] separator, int count)
' x. F* w2 ^' Y" C4 d6 F7 q2 x" G5 ]4 `+ k+ G; \7 @
程序代码: y! P/ _9 u0 b- G% e
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
' z# G4 f9 b1 W" }* Ystring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}; c" i, }, d+ K. l

# s: h8 a, O! Y4 N3. public string[] Split(char[] separator, StringSplitOptions options)
- I+ }) n8 [- z% @! W% B. s3 s/ s: ^  t0 M
程序代码1 \. o% [3 y5 [* t+ W( Y4 r
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
* a8 G& P- S/ n0 y- O6 }string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 }: J6 e4 U" P) Z9 O: P$ T( L0 `; s4 j; Y$ m1 t. ^; _
4. public string[] Split(string[] separator, StringSplitOptions options)
" e7 c8 K& ?5 R6 G  J
$ l  H, _4 X8 v0 K( q 程序代码2 f/ W7 I: X% e; ]. \
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
5 A# O- R6 S/ Xstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% a# i! x; b% T/ }# f/ R2 k; t: m+ o* A5 T6 @, ^
5. public string[] Split(char[] separator, int count, StringSplitOptions options)9 s) ?: v1 }" J* ~
) Z# @4 b+ v% u* e( u8 J% ^2 ~- `
程序代码
( b: c; `  a* I8 w+ n' U8 c' y" Pstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
+ ]1 ?, j( n. S# }% e% ystring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
7 |* Q7 Y2 U( U, d/ Q( r% y" f, _$ _, ?9 z
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
( g9 `) Z0 R0 D2 Q' c4 ~" A* H$ a8 `" j3 i9 [
代码
# ]* q" ?* q9 m. U! E" Rstring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! n1 ?' X6 j3 E0 Z  cstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-31 01:06 , Processed in 6.063709 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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