晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件8 o/ _* y+ S2 |8 _
' Y1 _- ~& A+ A# g$ v
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码, ~& M; n$ p+ z5 q& F; r3 ?
5 K4 ^2 F5 q2 a6 a6 y# P
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
4 x3 {3 L& U. {4 lhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
  w% {, ~+ ~6 Z9 a% ahttp://www.itwis.com/html/net/c/20100506/8234.html
, S% W2 d# q6 j4 ~; _' }. }3 \: P2 @* [+ M
程序代码* \7 o$ i8 Q- M
1) public string[] Split(params char[] separator)* k: \% o( V+ P) p; z8 v" ?5 }
2) public string[] Split(char[] separator, int count)
0 c& n1 Y0 S4 ?% Z( b3) public string[] Split(char[] separator, StringSplitOptions options)* L7 `( g! H* ^7 K& t- S4 S
4) public string[] Split(string[] separator, StringSplitOptions options)6 \6 s- n( ?( q& }- p
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
5 q) f$ @' C: c3 T8 o6) public string[] Split(string[] separator, int count, StringSplitOptions options)2 h/ N# |, `* i% k# T8 N0 r

& x, V( N: j% q" P2 t. _下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* z0 c$ E$ u- m" F- h1 q
8 K( L  R2 |6 g1 V6 H% j. }& d$ C
1. public string[] Split(params char[] separator)
' [4 D( q7 p" K, |" Q+ |" ?: a( h) e2 |/ l+ V1 _* ?: c% Q
程序代码3 C1 C4 ?8 Z* }3 A" F+ T# B/ u
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}- C7 n, u! k) d# M* T
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
- S3 W0 S3 W& r4 Y" m7 A3 k, ?9 M% J' m/ i% n3 ~
2. public string[] Split(char[] separator, int count)5 W1 G  W, R7 B' J4 e6 ^

9 H, \( |3 N4 @  T 程序代码/ ], w  o6 g( z2 J0 m+ J
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}) }& R; U- y  z3 Q# E7 I
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
/ {0 v& v' \8 T3 b9 p
5 Y; L0 H; J4 m  S8 J6 C. d3. public string[] Split(char[] separator, StringSplitOptions options)
$ z- ?$ X1 {1 C5 \4 L, i  [( s) p  N' F
程序代码
5 l% J) L7 q- ?( P& @string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
$ ~. ]$ W9 h" t9 }0 g2 L- kstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素/ K+ ^4 m7 n. f" k: M) x

: Q5 |1 Z& T! o* s4. public string[] Split(string[] separator, StringSplitOptions options)2 ~0 ~6 R: D. c6 W
7 P% F5 U- B+ F( m5 a* l! W
程序代码
1 B1 J! q5 C( t+ cstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
# x. F7 G$ |% C  T9 {string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素) S/ r& N# O4 p: n9 z
- A0 g( p4 \/ a; }
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
7 t& y3 R) Y( u( p
8 ], ?1 y4 y) P" V. ~ 程序代码
# P$ k* g- g& N4 v/ V+ g6 zstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素) O8 {! i6 ^& s  l  v, `& }1 h" j
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素: X9 ?4 v3 U, T  l+ p) e' @  Z

; H6 i% s& O0 r+ X& z8 P7 |6. public string[] Split(string[] separator, int count, StringSplitOptions options)- R: R8 X* U. b7 v7 F  J+ D

' U& o" l: {! n* d! ~- u3 @代码7 R0 E' i/ w. [+ T0 L3 s
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素. ]% x! B; n3 L
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-26 19:40 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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