晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
. u& ]' L8 k" U' x9 u/ F7 U# d9 K5 u
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
# D+ M* W% i) G3 B+ y( Y2 W4 |
+ J# d) G$ b# n% T% [6 g对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别7 }6 y5 h2 U1 O# W2 P; H0 ~" G+ }
http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
- F) f! V9 t7 X! K3 Q4 Nhttp://www.itwis.com/html/net/c/20100506/8234.html
. p$ ]# s0 L3 l+ Z, w5 Y$ J  o! u  Y% m4 Y
程序代码3 X7 T# n" I4 Z
1) public string[] Split(params char[] separator)! K$ C5 U5 D7 F7 P
2) public string[] Split(char[] separator, int count)( P6 v1 I! b: ?  D8 B. O9 Z
3) public string[] Split(char[] separator, StringSplitOptions options)
0 R2 P7 a! y3 ]9 O6 D& o4) public string[] Split(string[] separator, StringSplitOptions options)
4 _$ i) A6 \8 S, D/ Q9 u5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ l5 S! r1 R$ s! z, w6) public string[] Split(string[] separator, int count, StringSplitOptions options)
, ?0 N* r- U6 `) `; ?* W% U& R7 B7 S( a
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):$ ?- ^! S4 F# o% Y
# \2 i. }4 G4 u. _" L2 ~8 y
1. public string[] Split(params char[] separator)
* \* ?$ `& v& D7 \% C
) ?- S1 y# B+ G! a+ k' X/ I 程序代码
) o4 a: E1 o- ^7 y: Ostring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
, B- Q, P1 M& [! t' U5 Kstring[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}  T% b1 @. \* y7 F: c6 y

& u# o) Q! k# w: M/ Y! E! o2. public string[] Split(char[] separator, int count)0 t1 P( A: S- h, `" h$ p
! S" M& R; I+ d4 ?
程序代码4 h: @) r5 y. P4 h  @$ `4 _6 o
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
6 W5 M% m3 A: a( A, h2 Vstring[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
% H& F% {+ E8 j7 I) \7 C3 h7 h! a+ e/ c# z8 m1 S2 F" B% X
3. public string[] Split(char[] separator, StringSplitOptions options)
- @% `; S( G( H/ E0 D7 ?' D/ W! o/ d
$ K5 O" G1 T/ X% o4 q, C; H4 _/ j 程序代码
3 v# |/ P8 c9 ^8 N1 ystring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" u! S  b  v( i2 I. pstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 r! o7 J7 h; ^; Y
8 S1 m& Y, q4 v- A' j1 X4. public string[] Split(string[] separator, StringSplitOptions options); ^$ D, c) u& y3 {. y, n' Y

# p+ Q- ^5 T  p/ u 程序代码/ [, K$ _, l3 ^0 W6 Q/ P) N
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
) n9 E& Q$ X# f3 B9 Tstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素3 V* X/ h6 x4 v

+ g; N# F( \$ B* @. }4 R+ i, K) O7 {5. public string[] Split(char[] separator, int count, StringSplitOptions options)
% B' ~$ h) a8 z2 [
# E9 E, X1 |* M  e7 d4 ^6 f 程序代码5 W* N0 E/ Y' d7 e9 C$ Y; A/ w: x
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素( F  Q& v2 Q4 h; C$ F6 z! V9 t
string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
0 z/ u. _2 m  ^+ M+ n# ]6 K6 F2 T8 N
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
9 H! [7 H' ^, U# U3 R& K' M( v! e" q* x
代码7 `: g* ~3 j8 X0 Z* u! a, w
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素* w& C) H: v$ F5 C
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-16 20:33 , Processed in 6.071877 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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