晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件: ~1 v7 Y! u4 u; c9 b5 L
& Y4 G/ Z* [1 X; ~- h& E
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
7 ~- g9 G; M0 b5 r- w) k, \. [. M' J: ?& s8 [: y8 r9 K
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
1 q! G2 u4 b  n, I* A  [7 V: Uhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
& M4 x+ {' P2 L- ohttp://www.itwis.com/html/net/c/20100506/8234.html. q- i$ W* y6 a, `

# w( {- q. K* _% J2 p程序代码
# F8 M0 u- R' z, G( @' {% y9 I1) public string[] Split(params char[] separator)
+ ^$ Y. }5 \; s( @, l: u# g4 H2) public string[] Split(char[] separator, int count)" d: G' l8 u3 y. B
3) public string[] Split(char[] separator, StringSplitOptions options). {2 G) c& ]5 O  R  f
4) public string[] Split(string[] separator, StringSplitOptions options)
/ Q2 a2 I. l6 C; L6 ^5) public string[] Split(char[] separator, int count, StringSplitOptions options)
3 U6 z' a% D7 e0 ?! F6) public string[] Split(string[] separator, int count, StringSplitOptions options)
! ]( D0 A. p6 ]5 B: R6 T9 U# W3 o. t: @; k/ S( Q
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
2 F9 q* f, Q, K: e1 G2 L7 L4 c' Y# C: g& E
1. public string[] Split(params char[] separator)8 e! |% i* V, q

# I% A, ~% ?# d9 [! L2 k( U 程序代码
8 g! D2 ]! m# m2 gstring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
# R, X- Z9 S. s  e5 @0 b# Kstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
: D2 _; K3 p6 j- W& q! y5 Z7 F1 p/ {$ E
2. public string[] Split(char[] separator, int count)
& `- g& N- V' E- x+ [
7 d2 u, b* R; w 程序代码0 j; t: l- e3 e. D' n8 m" p. G
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}8 ?  ?# s" G+ }8 c9 x
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}% y) }% C$ Q" y
% B* w& h3 @+ ?
3. public string[] Split(char[] separator, StringSplitOptions options)
% e2 ^6 T) }# N, F5 c! _* R; a& S9 n+ E6 @0 {+ p, i& `
程序代码
( l' J* m! W6 J& Z- }) I, f2 Fstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
& R6 m* P' q5 q% mstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素" v4 t! j) k4 N. k
; v! u6 A% S! `2 L2 A
4. public string[] Split(string[] separator, StringSplitOptions options)! m4 Z2 Z0 V+ @, e

4 T1 B, e: d& ~& j 程序代码
1 g( o8 ~& q; W7 D. @string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素% R/ J/ _: I3 V* q* b
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
( u; {! h7 @# C0 C2 J/ v6 Y' Q- O9 {5 P, K4 y( |
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
+ d0 \/ Q/ `) r  q. ]
4 x% K: z% y' o( [+ D. [, @/ a 程序代码
2 G6 L0 {5 y% U3 S% k; Sstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 R6 y' U$ d/ E* a( zstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
# {3 d/ h- e& Z. ~. S. j, ]/ w6 P! K
6. public string[] Split(string[] separator, int count, StringSplitOptions options)9 p0 Y$ E% W, N8 g) v  Z
. f2 e+ ^0 J+ e8 ]* [
代码: |% ~! I0 E8 |3 Z7 c
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
5 b4 H. V% {* n2 E! K2 M6 Rstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-25 20:15 , Processed in 6.073476 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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