晨鸟科技

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

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

[复制链接]
跳转到指定楼层
楼主
发表于 2011-2-18 17:28:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当程序数据库发生修改后,需要执行sql脚本,以修正数据库。数据库连接字符串在web.config文件中,所以此部分设计两部分的内容:读web.config;执行sql脚本文件
* Q, H5 g! L' e! ]; Y3 W) l% z' @! ^3 v/ q( L! i& \; o" m& S
读web.config是以读xml文件的方式,找到connectingstring的value,对字符串进行切割、取子字符串的方式获取访问数据库的关键信息:数据库服务器名、数据库名、访问用户名、访问密码( T- g! o. L4 h* V/ Y( k
" N) v2 k, ]& c) c
对于脚本文件的执行,通过“GO”来获得脚本文件中包含的需要一次性执行的sql代码,然后再执行所有的代码块就好了
沙发
 楼主| 发表于 2011-2-18 17:33:01 | 只看该作者
这里是参考的这篇文章的做法,但是,这篇文章是用C#执行sql文件,再将连接字符串写到web.config中,和我的应用有些差别
& E6 ]: b& L/ t( ^- g& X# A1 e; Fhttp://blog.sina.com.cn/s/blog_4a50d85b0100lzi2.html
板凳
 楼主| 发表于 2011-2-18 17:37:45 | 只看该作者
下面的这篇文章,介绍了Split方法的各种重载的应用,并有例子,字符串切割的话可以看看8 C3 b# b, ^$ s* k
http://www.itwis.com/html/net/c/20100506/8234.html
# p! q6 G* J( @* w% k+ b& f6 v5 `8 M8 X' ]) a" M' Y( p1 m: [
程序代码
* G& y. v/ K0 R( V* Q6 M4 z: j# h& S1) public string[] Split(params char[] separator)
! C* z) `1 ~) {$ g# B/ O2) public string[] Split(char[] separator, int count)! N* ]+ G7 ?* r) K
3) public string[] Split(char[] separator, StringSplitOptions options)' L" b6 b6 y& T/ o0 w! ]/ m
4) public string[] Split(string[] separator, StringSplitOptions options)
. E0 R, j0 P1 q+ n5) public string[] Split(char[] separator, int count, StringSplitOptions options)
  H" \  z/ T# k6 s; e: c( X* Q6) public string[] Split(string[] separator, int count, StringSplitOptions options)
" I/ P! s( T& s; M, \+ b0 c8 s; g& O; ^: V7 i5 d! S
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, J2 E+ ]5 i( v: ^  }6 M7 [
" h8 l4 g1 b% G4 Z
1. public string[] Split(params char[] separator): j, h3 D7 Y! p2 q* W( [
7 [5 w  l3 X' e0 C) z" o
程序代码
% m# x% U9 x: _0 l& v7 estring[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}' m" F! _9 W" r
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}
& n% G+ U7 Q/ Y+ o+ ]6 M, c& z
7 x) F6 d( H2 G) c1 `/ y' h4 C2. public string[] Split(char[] separator, int count)6 I, x' i. F" c7 K& h6 z, k. {
" w1 q; V( x4 n) N
程序代码
# J2 ]+ Q6 a) D7 j$ G/ t+ dstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}- I  v, O4 @' T
string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}
( ^' E5 ?- G( g" y# O: `
; T/ N. D& E% F8 v5 A* F3. public string[] Split(char[] separator, StringSplitOptions options)2 z& H. Y- X9 E% I

% R  ?$ ~! h4 `$ V: e4 p 程序代码8 x# T7 p+ y) }  W4 ^* o1 X
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
" g* v8 k9 d9 u5 A& l6 T+ [string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
' ^& Q+ B; Q" [$ m; }. ^% q1 ~
' S) v% D7 Z+ V" `! I4. public string[] Split(string[] separator, StringSplitOptions options)3 R/ U/ P6 w+ M
7 ~" J  a6 L5 p( \1 Y5 y
程序代码# I- p% B6 c+ |, S% F) p( l
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素* \: ]9 q* x: X/ r: m1 @# Y
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素' E) w* f/ h! R2 B) S& n1 @* p

& @1 t; G8 C3 F) N* m" F! A5. public string[] Split(char[] separator, int count, StringSplitOptions options)2 ?" z! |5 v1 L; t. W

- G% R2 i. Z1 n2 d 程序代码5 E6 l+ q6 a5 i
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
2 p. r# |/ N! p3 q6 U  Y* Astring[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素* u, l0 H" D' H! p3 o

- ?) t' B9 w' O7 K1 q6. public string[] Split(string[] separator, int count, StringSplitOptions options)3 v$ \8 P, ^( B# ^6 k* C7 Y- B& S; r8 ]
4 M* g) f+ H3 j" w% j- a9 k
代码; {9 M  y) {, Y# I3 |1 v
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素: t, i& Z# {" v; ]  P2 Y
string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-29 15:55 , Processed in 6.066639 second(s), 8 queries , Wincache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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