晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
" d% x( [9 P1 o/ I  I9 C1 O) q+ y
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码
, C! w8 T. Q- u: L& B  m$ k, |/ l( U$ s5 V2 }; v9 g  v" b8 P
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
1 w+ }+ \* ?+ ^http://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看
: v& m8 C7 k) [9 Y$ phttp://www.itwis.com/html/net/c/20100506/8234.html
5 ?, s6 E- M, |' H: p
- S2 M+ ?: a6 {程序代码/ `" W# M6 J& Q7 F- \) B  o& ~1 }
1) public string[] Split(params char[] separator)3 T* `  P8 g( X- V4 h/ ]$ d; ?6 w, ]
2) public string[] Split(char[] separator, int count)3 N& K7 b9 I- P1 L/ A6 Y. R0 \
3) public string[] Split(char[] separator, StringSplitOptions options)
7 l% I& x0 ^$ k/ F9 ?* W) [4) public string[] Split(string[] separator, StringSplitOptions options)3 f. [$ Q& r! X) R( Q3 o' w8 s
5) public string[] Split(char[] separator, int count, StringSplitOptions options)
+ \5 W  a, x8 v, Z# s7 u6) public string[] Split(string[] separator, int count, StringSplitOptions options)- \& c5 r+ q" {7 D8 j* c" M
/ d% c) j$ Z, ^" Y1 |
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):* u3 ]/ U6 i# ]3 o) u

9 C2 ^6 P( |6 _4 v( f# D1. public string[] Split(params char[] separator)
/ L& C1 t4 Q; Y/ l9 b6 `) a! H
, |( w0 J2 ]( o+ w( ^8 F( l 程序代码3 t& `7 l3 Z. C* t2 J* R; K: h* f
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}3 M1 J' O- L5 G
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}  Q  v2 h3 {. }# y7 M
9 n6 i1 w( u7 W- B) N
2. public string[] Split(char[] separator, int count)! `# k6 I" v, W1 c

7 D: c# Y# C- C! C 程序代码. J4 j3 z- S* q0 S9 w5 c
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}4 ^" i9 B! B5 \. X4 e
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}+ P: D. J/ }2 _. z
) w4 I' C2 V% V- G
3. public string[] Split(char[] separator, StringSplitOptions options)& D; ]5 k( ]5 L) N9 v

$ ^! b) B; G& A5 v 程序代码9 O6 P* C* g/ T- ~! y( i
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素; Q. [" ]2 A+ z0 Q: e# L( z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
% m9 c. s9 j  g) Z0 v/ k8 E5 X
2 F$ B) c5 m( @5 V, J$ s7 @! ^4. public string[] Split(string[] separator, StringSplitOptions options)
4 t: q8 r0 G$ A# z2 |: I0 J
3 D0 ]+ X& e9 O8 y3 ?! t* v7 d 程序代码
4 f$ k; [! p) R. E) k! p( Tstring[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素# A# b* y( r9 m1 A6 g0 r
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
2 I' P. c' g7 T% ]- Z( X: ^6 p+ K% M( L1 K
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
4 w5 {- I7 T4 v" F$ I# o
. T( s3 `8 r! W6 Z, @ 程序代码
; t, o9 m9 b* p. Lstring[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
) S9 O! S1 q6 e; y* H  Fstring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& `# x1 M* o- i4 ?' z9 x
: S  e, i. y+ W  n* Y2 b8 f
6. public string[] Split(string[] separator, int count, StringSplitOptions options); [) f. o' O3 r7 g+ o8 Q, e- _- Q& r
1 W  ^; S$ X$ P9 e# k
代码' a% B! K& p1 p: U" n( {
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
7 P0 q9 Q0 Z! k0 E: [% ?$ gstring[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-9 02:13 , Processed in 6.063709 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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