晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件  S% x  `6 Y! j1 t# O

+ E/ O! F' p* n+ H5 z读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
/ ^& N" [8 Q/ Z* e/ T1 {. |7 e
. D: s7 ?/ s3 \8 W对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
) g  C4 K9 T4 _$ V) F! |5 \http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
6 ]& ~, \+ i# u% I' Vhttp://www.itwis.com/html/net/c/20100506/8234.html
1 p4 j- l! K4 d6 X6 J  t/ c) V( o8 [9 ?# w: S% }
程序代码! V- d, W7 v7 }9 ^# y
1) public string[] Split(params char[] separator)
7 ~1 ?  x: I; t+ p2) public string[] Split(char[] separator, int count)- j+ c1 b2 t# i( f4 Q
3) public string[] Split(char[] separator, StringSplitOptions options)
  f5 |% l4 [% G" o) x; a4) public string[] Split(string[] separator, StringSplitOptions options)  O. Z( i& o  [2 B9 R& C/ H
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
2 z" K+ C  O& K+ q1 N% M% [6) public string[] Split(string[] separator, int count, StringSplitOptions options)
3 s' u# f3 U4 o( y/ W) _
1 @  F; l" ]# u6 _  M" w7 ?# ]$ }下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):
  I+ m5 r, ?& f; g: D* ^
: d; H! z. q) |; H$ k0 Z, p: E1. public string[] Split(params char[] separator)
4 ?7 E3 b& k$ x8 D/ A2 s8 O) [
4 j3 F1 S, x+ ]) L% @3 G 程序代码5 g0 B: _  E2 \8 r. r5 _3 a( b% L
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}0 S( q. J/ R5 g/ B
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
3 [+ \$ x+ z# m( Q. `' \! t
- ~0 Q- v. r9 Y0 n- z2. public string[] Split(char[] separator, int count)2 e/ t9 ~- E  G$ D/ a

$ Y7 Z: `% }" T 程序代码  ^! x) h+ t& H6 B0 m' Y
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}& B, I6 ^% I  b# Q. g7 F& f
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}* {3 O4 f1 G6 b+ N  z( y- k* }

1 r$ L& S) ^$ ]9 p- a9 o% `3. public string[] Split(char[] separator, StringSplitOptions options)
5 C) r* {/ `9 q7 ?
; h" D+ Z# C! x. b3 G6 [5 G! L& q& u 程序代码
7 @: j9 b6 a' t4 U0 c9 @  hstring[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* Z  A5 x. p4 k0 a/ M7 k
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
* h2 n( ~' Q+ B* V5 j. _# Y! U2 e: j7 G" I! z+ O1 M* f* W
4. public string[] Split(string[] separator, StringSplitOptions options)
1 R8 {5 Y0 R) l# a* f! P$ f0 ]; ~# U
程序代码
! N9 n( q8 u) a4 U7 k; h1 q; tstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
* N( j4 \  }: M( ^4 Fstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
- T( b: L0 X5 s! x  I  B5 y8 G! x  P8 {8 Z1 N- v) h/ m# A! Y: k
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
3 U$ @9 a3 }) ~) D( m+ p2 t
' r: L2 w5 ]7 _) w: Z0 F 程序代码) T  @$ F( e$ c- K
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
8 D- d& B7 h% Q* w6 [+ Q" v8 v5 xstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素4 J. W$ ?5 [/ \+ q  [
* ^" V9 y9 E# P/ M3 X
6. public string[] Split(string[] separator, int count, StringSplitOptions options)
% F8 B: c* D% @) q. H# T( p: v4 M* G, r  X, ~* g8 W
代码
% ~( ~8 I& u9 ~/ q1 |6 K2 q! e: Istring[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
! O+ c$ O: ~! R" Ostring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-15 17:19 , Processed in 6.068593 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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